aboutsummaryrefslogtreecommitdiff
path: root/modules/base_installation/manifests/puppet.pp
blob: 603a96115b97493f9f4d71af639c059ed6537c60 (plain) (blame)
1
2
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
class base_installation::puppet (
  $password_seed = $base_installation::puppet_pass_seed
) inherits base_installation {
  File {
    mode  => "0600",
    owner => "root",
    group => "root",
  }

  exec { 'generate_password_seed':
    command     => "/usr/bin/openssl rand -base64 -out $password_seed 256",
    creates     => $password_seed,
    environment => "RANDFILE=/dev/null",
  }

  ### Until puppet fixes hist gettext-setup gem use
  package { 'gem:gettext-setup':
    name            => "gettext-setup",
    ensure          => present,
    provider        => "gem",
    install_options => "--no-user-install"
  }

  file { '/usr/lib/ruby/vendor_ruby/locales/':
    ensure => link,
    target => "/opt/puppetlabs/puppet/share/locale/",
  }
  ###

  file { '/usr/local/sbin/i_puppet_lock':
    mode   => "0755",
    ensure => present,
    source => "puppet:///modules/base_installation/scripts/puppet_lock"
  }

  file { '/usr/local/sbin/i_puppet_reset_and_apply':
    mode   => "0755",
    ensure => present,
    source => "puppet:///modules/base_installation/scripts/puppet_reset_and_apply"
  }

  file { '/usr/local/sbin/i_puppet_report_print':
    mode   => "0755",
    ensure => present,
    source => "puppet:///modules/base_installation/scripts/report_print.rb"
  }

  file { '/usr/local/sbin/puppet_apply':
    mode   => "0755",
    ensure => present,
    source => "puppet:///modules/base_installation/scripts/puppet_apply",
  }

  unless empty(find_file($password_seed)) {
    $ldap_password = generate_password(24, $password_seed, "ldap")
    $ssha_ldap_seed = generate_password(5, $password_seed, "ldap_seed")

    package { 'gem:ruby-ldap':
      name            => "ruby-ldap",
      ensure          => present,
      provider        => "gem",
      install_options => "--no-user-install"
    }

    package { 'gem:xmpp4r':
      name            => "xmpp4r",
      ensure          => present,
      provider        => "gem",
      install_options => "--no-user-install"
    }

    file { $password_seed:
      mode => "0600",
    }

    file { $base_installation::puppet_conf_path:
      ensure  => directory,
      require => [Package["puppet"], Package["gem:xmpp4r"], Package["gem:ruby-ldap"]],
      recurse => true,
      purge   => true,
      force   => true,
    }

    $xmpp = lookup("base_installation::notify_xmpp", { "default_value" => {} })
    $slack = lookup("base_installation::notify_slack", { "default_value" => {} })

    file { "$base_installation::puppet_conf_path/puppet.conf":
      content => template("base_installation/puppet/puppet.conf.erb"),
      require => File[$base_installation::puppet_conf_path],
    }

    unless empty($xmpp) {
      file { "$base_installation::puppet_conf_path/xmpp.yaml":
        content => template("base_installation/puppet/xmpp.yaml.erb"),
        require => File[$base_installation::puppet_conf_path],
      }
    }

    unless empty($slack) {
      file { "$base_installation::puppet_conf_path/slack.yaml":
        content => template("base_installation/puppet/slack.yaml.erb"),
        require => File[$base_installation::puppet_conf_path],
      }
    }

    if file("$base_installation::puppet_notifies_path/host_ldap.info", "/dev/null") != "" and
      empty($facts["ldapvar"]) {
        fail("LDAP was activated but facts are not available")
    }

    file { $base_installation::puppet_notifies_path:
      ensure  => directory,
      require => [Package["puppet"], Package["gem:xmpp4r"], Package["gem:ruby-ldap"]],
      recurse => true,
      purge   => true,
      force   => true,
    }

    $ips = lookup("ips", { 'default_value' => undef })
    concat { "$base_installation::puppet_notifies_path/host_ldap.info":
      ensure         => "present",
      mode           => "0600",
      require        => File[$base_installation::puppet_notifies_path],
      ensure_newline => true,
    }

    concat::fragment { "host_ldap add top":
      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
      content => template("base_installation/puppet/host_ldap_add_top.info.erb"),
      order   => "00-01",
    }
    concat::fragment { "host_ldap add bottom":
      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
      content => "EOF",
      order   => "00-99",
    }

    concat::fragment { "host_ldap mod top":
      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
      content => template("base_installation/puppet/host_ldap_mod_top.info.erb"),
      order   => "01-01",
    }
    concat::fragment { "host_ldap mod bottom":
      target  => "$base_installation::puppet_notifies_path/host_ldap.info",
      content => "EOF",
      order   => "01-99",
    }
  }
}