Defined Type: yum::gpgkey

Defined in:
manifests/gpgkey.pp

Summary

imports/deleted public GPG key for RPM. Key can be stored on Puppet's fileserver or as inline content.

Overview

Examples:

Sample usage:

yum::gpgkey { '/etc/pki/rpm-gpg/RPM-GPG-KEY-puppet-smoketest1':
  ensure  => 'present',
  content => '-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----';
}

Parameters:

  • path (String) (defaults to: $name)

    alternative file location (defaults to name)

  • ensure (Enum['present', 'absent']) (defaults to: 'present')

    specifies if key should be present or absent

  • content (Optional[String]) (defaults to: undef)

    the actual file content

  • source (Optional[String]) (defaults to: undef)

    source (e.g.: puppet:///)

  • owner (String) (defaults to: 'root')

    file owner

  • group (String) (defaults to: 'root')

    file group

  • mode (String) (defaults to: '0644')

    file mode



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
# File 'manifests/gpgkey.pp', line 21

define yum::gpgkey (
  String                    $path    = $name,
  Enum['present', 'absent'] $ensure  = 'present',
  Optional[String]          $content = undef,
  Optional[String]          $source  = undef,
  String                    $owner   = 'root',
  String                    $group   = 'root',
  String                    $mode    = '0644'
) {
  $_creators = [$content, $source]
  $_used_creators = $_creators.filter |$value| { !empty($value) }

  unless size($_used_creators) != 1 {
    File[$path] {
      content => $content,
      source  => $source,
    }
  } else {
    case size($_used_creators) {
      0:       { fail('Missing params: $content or $source must be specified') }
      default: { fail('You cannot specify more than one of content, source') }
    }
  }

  file { $path:
    ensure => $ensure,
    owner  => $owner,
    group  => $group,
    mode   => $mode,
  }

  $rpmname = "gpg-pubkey-$(gpg --with-colons ${path} | \
head -n 1 | \
cut -d: -f5 | \
cut -c9-16 | \
tr '[A-Z]' '[a-z]')"

  case $ensure {
    'present', default: {
      exec { "rpm-import-${name}":
        path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
        command => "rpm --import ${path}",
        unless  => "rpm -q ${rpmname}",
        require => File[$path],
      }
    }

    'absent': {
      exec { "rpm-delete-${name}":
        path    => '/bin:/usr/bin:/sbin/:/usr/sbin',
        command => "rpm -e ${rpmname}",
        onlyif  => ["test -f ${path}", "rpm -q ${rpmname}"],
        before  => File[$path],
      }
    }
  }
}