Puppet Class: hiera::eyaml

Inherits:
hiera::params
Defined in:
manifests/eyaml.pp

Overview

Class: hiera::eyaml

This class installs and configures hiera-eyaml

Authors:

Terri Haber <terri@puppetlabs.com>

Copyright © 2014 Terri Haber, unless otherwise noted.

Parameters:

  • provider (Any) (defaults to: $hiera::provider)
  • owner (Any) (defaults to: $hiera::owner)
  • group (Any) (defaults to: $hiera::group)
  • cmdpath (Any) (defaults to: $hiera::cmdpath)
  • confdir (Any) (defaults to: $hiera::confdir)
  • create_keys (Any) (defaults to: $hiera::create_keys)
  • eyaml_version (Any) (defaults to: $hiera::eyaml_version)
  • gem_source (Any) (defaults to: $hiera::gem_source)


13
14
15
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'manifests/eyaml.pp', line 13

class hiera::eyaml (
  $provider      = $hiera::provider,
  $owner         = $hiera::owner,
  $group         = $hiera::group,
  $cmdpath       = $hiera::cmdpath,
  $confdir       = $hiera::confdir,
  $create_keys   = $hiera::create_keys,
  $eyaml_version = $hiera::eyaml_version,
  $gem_source    = $hiera::gem_source,
) inherits hiera::params {

  $package_ensure = $eyaml_version ? {
    undef   => 'installed',
    default => $eyaml_version,
  }
  if $provider == 'pe_puppetserver_gem' {
    Exec {
      path => [
        '/opt/puppetlabs/server/bin',
        '/opt/puppetlabs/puppet/bin',
        '/opt/puppet/bin',
        '/usr/bin',
        '/bin',
      ],
    }

    $hiera_package_depedencies = [
      Exec['install ruby gem hiera-eyaml'],
      Exec['install puppetserver gem hiera-eyaml'],
    ]

    if $::pe_server_version {
      # PE 2015
      $vendored_gem_creates = '/opt/puppetlabs/puppet/bin/eyaml'
      $puppetserver_gem_creates = '/opt/puppetlabs/server/data/puppetserver/jruby-gems/bin/eyaml'
    } else {
      $vendored_gem_creates = '/opt/puppet/bin/eyaml'
      $puppetserver_gem_creates = '/var/opt/lib/pe-puppet-server/jruby-gems/bin/eyaml'
    }

    # The puppetserver gem wouldn't install the commandline util, so we do
    # that here
    #XXX Pre-puppet 4.0.0 version (PUP-1073)
    #BUG This can't actually update the gem version if already installed.
    if $eyaml_version and $eyaml_version =~ /^\d+\.\d+\.\d+$/ {
      $gem_flag = "--version ${eyaml_version}"
    } else {
      $gem_flag = undef
    }
    #XXX Post-puppet 4.0.0
    #package { 'hiera-eyaml command line':
    #  ensure   => installed,
    #  name     => 'hiera-eyaml',
    #  provider => 'pe_gem',
    #  source   => $gem_source,
    #}

    exec { 'install ruby gem hiera-eyaml':
      command => "gem install hiera-eyaml ${gem_flag}",
      creates => $vendored_gem_creates,
    }

    exec { 'install puppetserver gem hiera-eyaml':
      command => "puppetserver gem install hiera-eyaml ${gem_flag}",
      creates => $puppetserver_gem_creates,
      notify  => Service[$hiera::master_service],
    }
  } else {
    $hiera_package_depedencies = Package['hiera-eyaml']
    package { 'hiera-eyaml':
      ensure   => $package_ensure,
      provider => $provider,
      source   => $gem_source,
    }
  }

  File {
    owner => $owner,
    group => $group
  }

  file { "${confdir}/keys":
    ensure => directory,
  }

  if ( $create_keys == true ) {
    exec { 'createkeys':
      user    => $owner,
      cwd     => $confdir,
      command => 'eyaml createkeys',
      path    => $cmdpath,
      creates => "${confdir}/keys/private_key.pkcs7.pem",
      require => [ $hiera_package_depedencies, File["${confdir}/keys"] ]
    }

    file { "${confdir}/keys/private_key.pkcs7.pem":
      ensure  => file,
      mode    => '0600',
      require => Exec['createkeys'],
    }

    file { "${confdir}/keys/public_key.pkcs7.pem":
      ensure  => file,
      mode    => '0644',
      require => Exec['createkeys'],
    }
  }
}