Puppet Class: psick::puppetserver

Defined in:
manifests/puppetserver.pp

Overview

Parameters:

  • ensure (Variant[Boolean,String]) (defaults to: present)
  • module (Enum['psick', 'puppetserver']) (defaults to: 'psick')
  • r10k_remote_repo (Optional[String]) (defaults to: undef)
  • r10k_template (Optional[String]) (defaults to: 'psick/puppet/r10k/r10k.yaml.erb')
  • r10k_options (Hash) (defaults to: {})
  • r10k_configure_webhook (Boolean) (defaults to: true)
  • r10k_autodeploy (Boolean) (defaults to: true)
  • r10k_postrun_command (String) (defaults to: '/usr/local/bin/generate_types.sh')
  • r10k_postrun_source (String[1]) (defaults to: 'puppet:///modules/psick/puppet/generate_types.sh')
  • git_remote_repo (Optional[String]) (defaults to: undef)
  • dns_alt_names (String) (defaults to: "puppet,puppet.${::domain}")
  • remove_global_hiera_yaml (Boolean) (defaults to: false)


3
4
5
6
7
8
9
10
11
12
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'manifests/puppetserver.pp', line 3

class psick::puppetserver (

  Variant[Boolean,String]       $ensure = present,
  Enum['psick', 'puppetserver'] $module = 'psick',

  Optional[String]  $r10k_remote_repo     = undef,
  Optional[String]  $r10k_template        = 'psick/puppet/r10k/r10k.yaml.erb',
  Hash $r10k_options                      = {},
  Boolean $r10k_configure_webhook         = true,
  Boolean $r10k_autodeploy                = true,
  String $r10k_postrun_command            = '/usr/local/bin/generate_types.sh',
  String[1] $r10k_postrun_source          = 'puppet:///modules/psick/puppet/generate_types.sh',

  Optional[String]  $git_remote_repo      = undef,
  String            $dns_alt_names        = "puppet,puppet.${::domain}",
  Boolean           $remove_global_hiera_yaml = false,
) {

  # Installation management
  case $module {
    'psick': {
      contain ::psick::puppetserver::tp
      $puppetserver_class = 'psick::puppetserver::tp'
    }
    'puppetserver': {
      contain ::puppetserver
      $puppetserver_class = 'puppetserver'
    }
    default: {}
  }

  ini_setting { 'puppet master dns alt names':
    ensure  => present,
    path    => '/etc/puppetlabs/puppet/puppet.conf',
    section => 'master',
    setting => 'dns_alt_names',
    value   => $dns_alt_names,
    before  => Service['puppetserver'],
  }

  case $facts['puppetversion'] {
    /^(3|4|5)/: {
      # step 1 generate ca
      exec { '/opt/puppetlabs/puppet/bin/puppet cert list --all --allow-dns-alt-names':
        creates   => '/etc/puppetlabs/puppet/ssl/ca/ca_key.pem',
        logoutput => true,
        require   => [ Package['puppetserver'], Ini_setting['puppet master dns alt names'] ],
      }
      # step 2: generate host certificate
      exec { "/opt/puppetlabs/puppet/bin/puppet cert generate ${::facts['networking']['fqdn']}":
        creates   => "/etc/puppetlabs/puppet/ssl/certs/${::facts['networking']['fqdn']}.pem",
        logoutput => true,
        require   => [ Package['puppetserver'], Ini_setting['puppet master dns alt names'] ],
      }
    }
    /^(6)/: {
      # step 1 generate ca
      exec { "/opt/puppetlabs/bin/puppetserver ca setup --subject-alt-names ${dns_alt_names} --certname ${::facts['networking']['fqdn']}":
        creates   => '/etc/puppetlabs/puppet/ssl/ca/ca_key.pem',
        logoutput => true,
        require   => [ Package['puppetserver'], Ini_setting['puppet master dns alt names'] ],
      }
    }
    default: { }
  }

  if $r10k_remote_repo or $r10k_options {
    # r10k gem is expected to be already installed
    # for example by psick::puppet::gems
    # He we configure just r10k.yaml and eventually the webhook
    # using puppetlabs-r10k module
    $r10k_sources  = {
      'puppet' => {
        'remote'  => $r10k_remote_repo,
        'basedir' => '/etc/puppetlabs/code/environments',
      }
    }
    $r10k_default_options = {
      postrun         => [$r10k_postrun_command],
      cachedir        => "${facts['puppet_vardir']}/r10k",
      sources         => $r10k_sources,
      source_keys     => keys($r10k_sources),
      deploy_settings => {},
      git_settings    => {},
      forge_settings  => {},
    }
    $r10k_real_options = $r10k_default_options + $r10k_options
    if $r10k_template {
      file { '/etc/puppetlabs/r10k':
        ensure => directory,
      }
      file { '/etc/puppetlabs/r10k/r10k.yaml':
        ensure  => present,
        content => template($r10k_template),
      }
      file { $r10k_postrun_command:
        ensure => file,
        mode   => '0755',
        source => $r10k_postrun_source,
      }
    }
    if $r10k_autodeploy and $r10k_template {
      exec { 'r10k deploy environment':
        path        => '/opt/puppetlabs/puppet/bin',
        refreshonly => true,
        subscribe   => File['/etc/puppetlabs/r10k/r10k.yaml'],
      }
    }
    if $r10k_configure_webhook {
      class {'r10k::webhook::config':
        enable_ssl      => false,
        use_mcollective => false,
        require         => Class['r10k'],
      }
      class {'r10k::webhook':
        use_mcollective => false,
        user            => 'root',
        group           => '0',
        require         => Class['r10k::webhook::config'],
      }
    }
  }

  if $git_remote_repo {
    exec { 'remove default controlrepo':
      command => 'mv /etc/puppetlabs/code/environments/production /etc/puppetlabs/code/environments/production.default',
      creates => '/etc/puppetlabs/code/environments/production.default',
      before  => Tp::Dir['puppet::control-repo'],
    }
    tp::dir { 'puppet::control-repo':
      path               => '/etc/puppetlabs/code/environments/production',
      vcsrepo            => 'git',
      source             => $git_remote_repo,
      config_dir_notify  => false,
      config_dir_require => false,
      notify             => Exec['r10k puppetfile install'],
    }
    exec { 'r10k puppetfile install':
      command     => 'r10k puppetfile install',
      cwd         => '/etc/puppetlabs/code/environments/production',
      path        => '/opt/puppetlabs/puppet/bin:/usr/bin',
      refreshonly => true,
      # require     => Package['r10k'],
    }
  }

  if $remove_global_hiera_yaml {
    file { '/etc/puppetlabs/puppet/hiera.yaml':
      ensure => absent,
    }
  }
}