bodgit / puppet-yum

Puppet Module for managing Yum
https://forge.puppet.com/bodgit/yum
Apache License 2.0
0 stars 1 forks source link

[RFC] COPR support #10

Open olifre opened 4 years ago

olifre commented 4 years ago

This module does not have support for COPR yet, i.e. repos from https://copr.fedorainfracloud.org which are handled via yum-plugin-copr or dnf-plugins-core.

This is an RFC to find out if:

To trigger off discussion a bit, I am currently using a custom ressource defined like this:

define profile::repo::copr(
        String                                  $copr_repo      = $title,
        Enum['enabled', 'disabled', 'removed']  $ensure         = 'enable',
) {
  $prereq_plugin = $facts['package_provider'] ? {
    'dnf'   => 'dnf-plugins-core',
    default => 'yum-plugin-copr',
  }
  ensure_packages([ $prereq_plugin ])
  if $facts['package_provider'] == 'dnf' {
    case $ensure {
      'enabled':
        {
          exec { "dnf -y copr enable ${copr_repo}":
            unless  => "dnf copr list | egrep -q '${copr_repo}\$'",
            require => Package[$prereq_plugin],
          }
        }
      'disabled':
        {
          exec { "dnf -y copr disable ${copr_repo}":
            unless  => "dnf copr list | egrep -q '${copr_repo} (disabled)\$'",
            require => Package[$prereq_plugin],
          }
        }
      'removed':
        {
          exec { "dnf -y copr remove ${copr_repo}":
            unless  => "dnf copr list | egrep -q '${copr_repo}'",
            require => Package[$prereq_plugin],
          }
        }
    }
  } else {
    $copr_repo_name_part = regsubst($copr_repo, '/', '-', 'G')
    case $ensure {
      'enabled':
        {
          exec { "yum -y copr enable ${copr_repo}":
            onlyif  => "test ! -e /etc/yum.repos.d/_copr_${copr_repo_name_part}.repo",
          }
        }
      'disabled', 'removed':
        {
          exec { "yum -y copr disable ${copr_repo}":
            onlyif  => "test -e /etc/yum.repos.d/_copr_${copr_repo_name_part}.repo",
          }
        }
    }
  }
}

which allows me to do:

profile::repo::copr { 'copart/restic':
  ensure  => 'enabled',
}
bodgit commented 4 years ago

Interesting. What is yum/dnf -y copr ... doing behind the scenes? Is it just creating a repo configuration in /etc/yum.repos.d/?

I want to make sure this module works on EL8 properly first, now that a vagrant box is available for testing but I will definitely think about including this as an enhancement. I wasn't aware there was a specific plugin for COPR.

olifre commented 4 years ago

What is yum/dnf -y copr ... doing behind the scenes? Is it just creating a repo configuration in /etc/yum.repos.d/?

Effectively, yes. Here's the upstream code: https://github.com/rpm-software-management/yum-utils/blob/master/plugins/copr/copr.py https://github.com/rpm-software-management/dnf-plugins-core/blob/master/plugins/copr.py The code is much more lengthy and can also handly playground repos, list installed repos, checks if the repo exists, fetches the repo file from COPR, shows a warning that this is community maintained etc.

I want to make sure this module works on EL8 properly first

Fully agreed :-). I'm already using it on a few machines running CentOS 8, but we're not using the full functionality.