Puppet Class: psick::bolt::master

Defined in:
manifests/bolt/master.pp

Summary

Manages bolt configurations on node from where bolt tasks

Overview

are inkoved

Parameters:

  • ensure (Variant[Boolean,String]) (defaults to: 'present')
  • install_package (Boolean) (defaults to: true)
  • install_system_gems (Boolean) (defaults to: false)
  • install_puppet_gems (Boolean) (defaults to: false)
  • user_password (Optional[String]) (defaults to: undef)
  • user_home (Optional[String]) (defaults to: undef)
  • create_bolt_user (Boolean) (defaults to: true)
  • run_ssh_keygen (Boolean) (defaults to: true)
  • fact_template (String) (defaults to: 'psick/bolt/bolt_user_key.sh.erb')
  • inventory_epp (Variant[Undef,String]) (defaults to: undef)
  • generate_nodes_list (Boolean) (defaults to: true)
  • nodes_list_hash (Hash) (defaults to: {})
  • manage (Boolean) (defaults to: $psick::manage)
  • noop_manage (Boolean) (defaults to: $psick::noop_manage)
  • noop_value (Boolean) (defaults to: $psick::noop_value)


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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'manifests/bolt/master.pp', line 4

class psick::bolt::master (

  Variant[Boolean,String] $ensure        = 'present',

  # Management of bolt installation
  Boolean $install_package     = true,
  Boolean $install_system_gems = false,
  Boolean $install_puppet_gems = false,

  # Management of user running bolt
  Optional[String]        $user_password    = undef,
  Optional[String]        $user_home        = undef,
  Boolean                 $create_bolt_user = true,
  Boolean                 $run_ssh_keygen   = true,
  String                  $fact_template    = 'psick/bolt/bolt_user_key.sh.erb',

  # Management of automatic host list files used by bolt command
  Variant[Undef,String]   $inventory_epp = undef,
  Boolean $generate_nodes_list           = true,
  Hash $nodes_list_hash                  = {},

  Boolean          $manage               = $psick::manage,
  Boolean          $noop_manage          = $psick::noop_manage,
  Boolean          $noop_value           = $psick::noop_value,

) {
  if $manage {
    if $noop_manage {
      noop($noop_value)
    }

    $dir_ensure = ::tp::ensure2dir($ensure)

    include psick::bolt

    # Bolt installation
    if $install_system_gems {
      if $psick::bolt::auto_prereq {
        include psick::ruby
        include psick::ruby::buildgems
      }
      package { 'bolt':
        ensure   => $ensure,
        provider => 'gem',
        require  => [Class['psick::ruby'],Class['psick::ruby::buildgems']],
      }
    }
    if $install_puppet_gems {
      package { 'bolt':
        ensure   => $ensure,
        provider => 'puppet_gem',
      }
    }

    if $install_package {
      package { 'bolt':
        ensure   => $ensure,
      }
    }

    # Management of the user running bolt
    $user_home_dir = $user_home ? {
      undef   => $psick::bolt::bolt_user ? {
        'root'    => '/root',
        default => "/home/${psick::bolt::bolt_user}",
      },
      default => $user_home
    }

    if $create_bolt_user {
      user { $psick::bolt::bolt_user:
        ensure     => $ensure,
        comment    => 'Puppet managed bolt user',
        managehome => true,
        shell      => '/bin/bash',
        home       => $user_home_dir,
        password   => $user_password,
      }
    }

    $ssh_dir_require = $create_bolt_user ? {
      true  => User[$psick::bolt::bolt_user],
      false => undef,
    }

    if $run_ssh_keygen or $psick::bolt::bolt_user_pub_key {
      file { "${user_home_dir}/.ssh" :
        ensure  => $dir_ensure,
        mode    => '0700',
        owner   => $psick::bolt::bolt_user,
        group   => $psick::bolt::bolt_group,
        require => $ssh_dir_require,
      }
    }

    if $run_ssh_keygen {
      psick::openssh::keygen { $psick::bolt::bolt_user:
        require => File["${user_home_dir}/.ssh"],
      }
      psick::puppet::set_external_fact { 'bolt_user_key.sh':
        template => $fact_template,
        mode     => '0755',
      }
    }

    if $psick::bolt::keyshare_method == 'storeconfigs'
    and defined('psick::bolt::bolt_user_pub_key')
    or defined('bolt_user_key') {
      @@ssh_authorized_key { "bolt_user_${psick::bolt::ssh_user}_rsa-${facts['clientcert']}":
        ensure => $ensure,
        key    => pick($psick::bolt::bolt_user_pub_key,getvar('facts.bolt_user_key')),
        user   => $psick::bolt::ssh_user,
        type   => 'rsa',
        tag    => "bolt_master_${psick::bolt::master}_${psick::bolt::bolt_user}",
      }
      Sshkey <<| tag == "bolt_node_${psick::bolt::master}_rsa" |>>
    }

    if $psick::bolt::bolt_user_pub_key and $psick::bolt::bolt_user_priv_key {
      file { "${user_home_dir}/.ssh/id_rsa.pub":
        ensure  => $dir_ensure,
        mode    => '0700',
        owner   => $psick::bolt::bolt_user,
        group   => $psick::bolt::bolt_group,
        content => $psick::bolt::bolt_user_pub_key,
      }
      file { "${user_home_dir}/.ssh/id_rsa":
        ensure  => $dir_ensure,
        mode    => '0700',
        owner   => $psick::bolt::bolt_user,
        group   => $psick::bolt::bolt_group,
        content => $psick::bolt::bolt_user_priv_key,
      }
    }

    if $generate_nodes_list {
      $nodes_query = "nodes { certname ~ '.*' }"
      $nodes = puppetdb_query($nodes_query)
      $nodes_list = $nodes.map |$node| { $node['certname'] }
      $nodes_csv = join($nodes_list.sort,',')

      file { "${user_home_dir}/nodes":
        ensure => $dir_ensure,
        owner  => $psick::bolt::bolt_user,
        group  => $psick::bolt::bolt_group,
      }
      $default_file_options = {
        ensure => $ensure,
        owner  => $psick::bolt::bolt_user,
        group  => $psick::bolt::bolt_group,
      }
      $default_nodes_lists_hash = {
        'all' => {
          content => $nodes_csv,
        },
      }
      $full_nodes_list_hash = $default_nodes_lists_hash + $nodes_list_hash
      $full_nodes_list_hash.each | $k,$v | {
        file { "${user_home_dir}/nodes/${k}":
          * => $default_file_options + $v,
        }
      }
    }
  }
}