Defined Type: yum::copr

Defined in:
manifests/copr.pp

Summary

This definition manages Copr (Cool Other Package Repo) repositories.

Overview

Examples:

add and enable COPR restic repository

yum::copr { 'copart/restic':
  ensure  => 'enabled',
}

Parameters:

  • copr_repo (String) (defaults to: $title)

    Name of repository, defaults to title.

  • manage_prereq_plugin (Boolean) (defaults to: true)

    Wheter required plugin for dnf/yum should be installed by this resource.

  • ensure (Enum['enabled', 'disabled', 'removed']) (defaults to: 'enabled')

    Specifies if repo should be enabled, disabled or removed.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'manifests/copr.pp', line 16

define yum::copr (
  String                                 $copr_repo            = $title,
  Boolean                                $manage_prereq_plugin = true,
  Enum['enabled', 'disabled', 'removed'] $ensure               = 'enabled',
) {
  $prereq_plugin = $facts['package_provider'] ? {
    'dnf'   => 'dnf-plugins-core',
    default => 'yum-plugin-copr',
  }
  if $manage_prereq_plugin {
    stdlib::ensure_packages([$prereq_plugin])
  }

  if $facts['package_provider'] == 'dnf' {
    case $ensure {
      'enabled': {
        exec { "dnf -y copr enable ${copr_repo}":
          path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
          unless  => "dnf copr list | egrep -q '${copr_repo}\$'",
          require => Package[$prereq_plugin],
        }
      }
      'disabled': {
        exec { "dnf -y copr disable ${copr_repo}":
          path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
          unless  => "dnf copr list | egrep -q '${copr_repo} (disabled)\$'",
          require => Package[$prereq_plugin],
        }
      }
      'removed': {
        exec { "dnf -y copr remove ${copr_repo}":
          path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
          onlyif  => "dnf copr list | egrep -q '${copr_repo}'",
          require => Package[$prereq_plugin],
        }
      }
      default: {
        fail("The value for ensure for `yum::copr` must be enabled, disabled or removed, but it is ${ensure}.")
      }
    }
  } else {
    $copr_repo_name_part = regsubst($copr_repo, '/', '-', 'G')
    case $ensure {
      'enabled': {
        exec { "yum -y copr enable ${copr_repo}":
          path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
          onlyif  => "test ! -e /etc/yum.repos.d/_copr_${copr_repo_name_part}.repo",
          require => Package[$prereq_plugin],
        }
      }
      'disabled', 'removed': {
        exec { "yum -y copr disable ${copr_repo}":
          path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
          onlyif  => "test -e /etc/yum.repos.d/_copr_${copr_repo_name_part}.repo",
          require => Package[$prereq_plugin],
        }
      }
      default: {
        fail("The value for ensure for `yum::copr` must be enabled, disabled or removed, but it is ${ensure}.")
      }
    }
  }
}