Puppet Class: psick::puppet::foss_master

Defined in:
manifests/puppet/foss_master.pp

Overview

Class psick::puppet::foss_master

this class bootstraps a Puppet Open Source master

example usage:

contain psick::puppet::foss_master

class { 'psick::puppet::foss_master':
  r10k_repmote_repo = 'https://github.com/example42/psick.git'
}

TODO:

  • make all default repos optional

  • ensure DNS alt names are possible for puppet server

  • separate puppetdb host

  • separate postgresql host

  • allow multi master setup

  • allow multiple control-repos

Parameters:

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

    specify the git URL to your control repo

  • manage_puppetdb_repo (Boolean) (defaults to: true)
  • enable_puppetdb (Boolean) (defaults to: true)
  • git_remote_repo (Optional[String]) (defaults to: undef)
  • enable_puppetdb_sslsetup (Boolean) (defaults to: false)
  • dns_alt_names (String) (defaults to: "puppet,puppet.${facts['networking']['domain']}")
  • remove_global_hiera_yaml (Boolean) (defaults to: false)
  • manage (Boolean) (defaults to: $psick::manage)
  • noop_manage (Boolean) (defaults to: $psick::noop_manage)
  • noop_value (Boolean) (defaults to: $psick::noop_value)


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
# File 'manifests/puppet/foss_master.pp', line 25

class psick::puppet::foss_master (
  Optional[String]  $r10k_remote_repo         = undef,
  Optional[String]  $git_remote_repo          = undef,
  Boolean           $manage_puppetdb_repo     = true,
  Boolean           $enable_puppetdb_sslsetup = false,
  Boolean           $enable_puppetdb          = true,
  String            $dns_alt_names            = "puppet,puppet.${facts['networking']['domain']}",
  Boolean           $remove_global_hiera_yaml = false,
  Boolean $manage                  = $psick::manage,
  Boolean $noop_manage             = $psick::noop_manage,
  Boolean $noop_value              = $psick::noop_value,
) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }
    if versioncmp('5', $facts['puppetversion']) > 0 {
      $postgresversion = '9.4'
    } else {
      $postgresversion = '9.6'
    }

    contain puppetserver
    # Workflow: create puppetserver ssl ca and certificates
    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,
    }

    case $facts['puppetversion'] {
      /^(3|4|5)/: {
        $cert_list_command = '/opt/puppetlabs/puppet/bin/puppet cert list --all --allow-dns-alt-names'
        $cert_generate_command = "/opt/puppetlabs/puppet/bin/puppet cert generate ${facts['networking']['fqdn']}"
      }
      default: {
        $cert_list_command = undef
        $cert_generate_command =  '/opt/puppetlabs/bin/puppetserver ca setup'
      }
    }

    if $cert_list_command {
      exec { $cert_list_command:
        creates   => '/etc/puppetlabs/puppet/ssl/ca/ca_key.pem',
        logoutput => true,
        require   => [Package['puppetserver'], Ini_setting['puppet master dns alt names']],
      }
    }
    if $cert_generate_command {
      exec { $cert_generate_command:
        creates   => "/etc/puppetlabs/puppet/ssl/certs/${facts['networking']['fqdn']}.pem",
        logoutput => true,
        require   => [Package['puppetserver'], Ini_setting['puppet master dns alt names']],
      }
    }

    if $r10k_remote_repo {
      class { 'r10k':
        remote   => $r10k_remote_repo,
        provider => 'puppet_gem',
      }
      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 $enable_puppetdb {
      class { 'puppetdb':
        manage_firewall     => false,
        manage_package_repo => $manage_puppetdb_repo,
        ssl_protocols       => 'TLSv1.2',
        postgres_version    => $postgresversion,
      }
      class { 'puppetdb::master::config':
        manage_report_processor => true,
        enable_reports          => true,
        restart_puppet          => false,
        require                 => Service['puppetserver'],
      }
      if $enable_puppetdb_sslsetup {
        exec { 'puppetdb ssl-setup':
          command => '/opt/puppetlabs/bin/puppetdb ssl-setup',
          creates => '/etc/puppetlabs/puppetdb/ssl/private.pem',
          require => Package['puppetdb'],
          notify  => Service['puppetdb'],
        }
      }
    }

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