Puppet Class: hiera::eyaml

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.



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
121
122
123
124
125
126
127
# 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
  $_keysdir      = $hiera::_keysdir
  $eyaml_version = $hiera::eyaml_version
  $gem_source    = $hiera::gem_source

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

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

    # The puppetserver gem wouldn't install the commandline util, so we do
    # that here (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
    }

    exec { 'install ruby gem hiera-eyaml':
      command => "gem install hiera-eyaml ${gem_flag}",
      creates => '/opt/puppet/bin/eyaml',
    }

    exec { 'install puppetserver gem hiera-eyaml':
      command => "puppetserver gem install hiera-eyaml ${gem_flag}",
      creates => '/var/opt/lib/pe-puppet-server/jruby-gems/bin/eyaml',
    }
    $master_subscribe = Exec['install puppetserver gem hiera-eyaml']
  } elsif $provider == 'puppetserver_gem' {
    $hiera_package_depedencies = [
      Package['hiera-eyaml'],
      Package['puppetserver hiera-eyaml'],
    ]
    package { 'puppetserver hiera-eyaml':
      ensure   => $package_ensure,
      name     => 'hiera-eyaml',
      provider => $provider,
      source   => $gem_source,
    }
    package { 'hiera-eyaml':
      ensure   => $package_ensure,
      provider => 'puppet_gem',
      source   => $gem_source,
    }
    $master_subscribe = [
      Package['hiera-eyaml'],
      Package['puppetserver hiera-eyaml']
    ]
  } else {
    $hiera_package_depedencies = Package['hiera-eyaml']
    package { 'hiera-eyaml':
      ensure   => $package_ensure,
      provider => $provider,
      source   => $gem_source,
    }
    $master_subscribe = Package['hiera-eyaml']
  }
  Service <| title == $hiera::master_service |> {
    subscribe +> $master_subscribe,
  }

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

  file { $_keysdir:
    ensure => directory,
  }

  $keysdir = dirname($_keysdir)

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

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

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