summaryrefslogtreecommitdiff
path: root/sitemodules/profiles/manifests/icinga2_master.pp
blob: d1c26e77ca58e4c183d8b45da1ed6243e516d45f (plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# Class: profiles::icinga2_master
# ===============================
#
# This class installs and configures the Icinga2 master with
# PostgreSQL IDO backend
#
# Parameters
# ----------
#
# @param ido_database_name      database name for Icinga2 IDO
# @param ido_database_user      database user for Icinga2 IDO
# @param ido_database_password  database password for Icinga2 IDO
# @param web2_database_name     database name for IcingaWeb2 database
# @param web2_database_user     database user for IcingaWeb2 database
# @param web2_database_password database password for IcingaWeb2 database
# @param icinga2_ticket_salt    salt for certificate request tickets for
#                               Icinga2 node authentication
# @param api_users              Icinga2 API users
# @param ca_key                 Icinga2 CA private key content
# @param ca_certificate         Icinga2 CA certificate content
# @param host_key               Icinga2 host private key content
# @param host_certificate       Icinga2 host certificate content
# @param host_csr               Icinga2 host certificate signing request
#                               content
#
# Examples
# --------
#
# @example
#   class roles::myhost {
#     include profiles::icinga2_master
#   }
#
# Authors
# -------
#
# Jan Dittberner <jandd@cacert.org>
#
# Copyright
# ---------
#
# Copyright 2019 Jan Dittberner
class profiles::icinga2_master (
  String $ido_database_name,
  String $ido_database_user,
  String $ido_database_password,
  String $web2_database_name,
  String $web2_database_user,
  String $web2_database_password,
  String $icinga2_ticket_salt,
  Array[Hash[String, Variant[String, Tuple[String, 1]]]] $api_users,
  String $ca_key,
  String $ca_certificate,
  String $host_key,
  String $host_certificate,
  String $host_csr,
) {
  include 'profiles::icinga2_common'

  debconf { 'icinga2-ido-pgsql/pgsql/app-pass':
    package => 'icinga2-ido-pgsql',
    type    => 'password',
    value   => $ido_database_password,
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/app-password-confirm':
    package => 'icinga2-ido-pgsql',
    type    => 'password',
    value   => $ido_database_password,
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/remote/host':
    package => 'icinga2-ido-pgsql',
    value   => 'localhost',
    type    => 'string',
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/db/dbname':
    package => 'icinga2-ido-pgsql',
    value   => $ido_database_name,
    type    => 'string',
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/db/app-user':
    package => 'icinga2-ido-pgsql',
    value   => "${ido_database_user}@localhost",
    type    => 'string',
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/enable':
    package => 'icinga2-ido-pgsql',
    type    => 'boolean',
    value   => 'true', # lint:ignore:quoted_booleans
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/dbconfig-reinstall':
    package => 'icinga2-ido-pgsql',
    type    => 'boolean',
    value   => 'false', # lint:ignore:quoted_booleans
    seen    => true,
  }
  debconf { 'icinga2-ido-pgsql/dbconfig-install':
    package => 'icinga2-ido-pgsql',
    type    => 'boolean',
    value   => 'true', # lint:ignore:quoted_booleans
    seen    => true,
  }
  package { 'icinga2-ido-pgsql':
    ensure  => latest,
    require => [
      Debconf['icinga2-ido-pgsql/pgsql/app-pass'],
      Debconf['icinga2-ido-pgsql/app-password-confirm'],
      Debconf['icinga2-ido-pgsql/remote/host'],
      Debconf['icinga2-ido-pgsql/db/dbname'],
      Debconf['icinga2-ido-pgsql/db/app-user'],
      Debconf['icinga2-ido-pgsql/enable'],
      Debconf['icinga2-ido-pgsql/dbconfig-reinstall'],
      Debconf['icinga2-ido-pgsql/dbconfig-install'],
    ],
  }
  file { '/etc/icinga2/constants.conf':
    ensure  => file,
    content => epp('profiles/icinga2_master/constants.conf.epp', {
      'ticket_salt' => $icinga2_ticket_salt
    }),
    owner   => 'root',
    group   => 'nagios',
    mode    => '0640',
    require => Package['icinga2'],
  }
  file { '/etc/icinga2/icinga2.conf':
    ensure => file,
    source => 'puppet:///modules/profiles/icinga2_master/icinga2.conf',
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
  }
  file { '/etc/icinga2/init.conf':
    ensure => file,
    source => 'puppet:///modules/profiles/icinga2_master/init.conf',
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
  }
  file { '/etc/icinga2/features-available/api.conf':
    ensure  => file,
    content => epp('profiles/icinga2_master/features-available/api.conf.epp'),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package['icinga2'],
  }
  file { '/etc/icinga2/features-available/checker.conf':
    ensure  => file,
    source  => 'puppet:///modules/profiles/icinga2_master/features-available/checker.conf',
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package['icinga2'],
  }
  file { '/etc/icinga2/features-available/ido-pgsql.conf':
    ensure  => file,
    content => epp('profiles/icinga2_master/features-available/ido-pgsql.conf.epp', {
      'db_name'     => $ido_database_name,
      'db_user'     => $ido_database_user,
      'db_password' => $ido_database_password
    }),
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0600',
    require => [Package['icinga2'], Package['icinga2-ido-pgsql']],
  }
  file { '/etc/icinga2/features-available/mainlog.conf':
    ensure  => file,
    source  => 'puppet:///modules/profiles/icinga2_master/features-available/mainlog.conf',
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package['icinga2'],
  }
  file { '/etc/icinga2/features-enabled/api.conf':
    ensure => link,
    target => '/etc/icinga2/features-available/api.conf',
    owner  => 'root',
    group  => 'root',
  }
  file { '/etc/icinga2/features-enabled/checker.conf':
    ensure => link,
    target => '/etc/icinga2/features-available/checker.conf',
    owner  => 'root',
    group  => 'root',
  }
  file { '/etc/icinga2/features-enabled/ido-pgsql.conf':
    ensure => link,
    target => '/etc/icinga2/features-available/ido-pgsql.conf',
    owner  => 'root',
    group  => 'root',
  }
  file { '/etc/icinga2/features-enabled/mainlog.conf':
    ensure => link,
    target => '/etc/icinga2/features-available/mainlog.conf',
    owner  => 'root',
    group  => 'root',
  }
  file { '/etc/icinga2/features-enabled/notification.conf':
    ensure => link,
    target => '/etc/icinga2/features-available/notification.conf',
    owner  => 'root',
    group  => 'root',
  }
  file { '/etc/icinga2/zones.conf':
    ensure  => file,
    content => epp('profiles/icinga2_master/zones.conf.epp'),
    owner   => 'root',
    group   => 'root',
    mode    => '0644',
    require => Package['icinga2'],
  }
  file { '/etc/icinga2/conf.d/api-users.conf':
    ensure  => file,
    content => epp('profiles/icinga2_master/conf.d/api-users.conf.epp', {
      'api_users' => $api_users
    }),
    owner   => 'root',
    group   => 'nagios',
    mode    => '0640',
    require => Package['icinga2'],
  }
  file { '/var/lib/icinga2/ca':
    ensure  => directory,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0700',
    require => Package['icinga2'],
  }
  file { '/var/lib/icinga2/ca/ca.key':
    ensure  => file,
    content => $ca_key,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0600',
    require => File['/var/lib/icinga2/ca'],
  }
  file { '/var/lib/icinga2/ca/ca.crt':
    ensure  => file,
    content => $ca_certificate,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0644',
    require => File['/var/lib/icinga2/ca'],
  }
  file { '/etc/icinga2/pki':
    ensure  => directory,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0700',
    require => Package['icinga2'],
  }
  file { '/etc/icinga2/pki/ca.crt':
    ensure  => file,
    content => $ca_certificate,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0644',
    require => File['/etc/icinga2/pki'],
  }
  file { "/etc/icinga2/pki/${facts['fqdn']}.key":
    ensure  => file,
    content => $host_key,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0600',
    require => File['/etc/icinga2/pki'],
  }
  file { "/etc/icinga2/pki/${facts['fqdn']}.crt":
    ensure  => file,
    content => $host_certificate,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0644',
    require => File['/etc/icinga2/pki'],
  }
  file { "/etc/icinga2/pki/${facts['fqdn']}.csr":
    ensure  => file,
    content => $host_csr,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0644',
    require => File['/etc/icinga2/pki'],
  }
  service { 'icinga2':
    ensure    => 'running',
    enable    => true,
    subscribe => [
      File['/etc/icinga2/constants.conf'],
      File['/etc/icinga2/icinga2.conf'],
      File['/etc/icinga2/init.conf'],
      File['/etc/icinga2/features-enabled/api.conf'],
      File['/etc/icinga2/features-enabled/checker.conf'],
      File['/etc/icinga2/features-enabled/ido-pgsql.conf'],
      File['/etc/icinga2/features-enabled/mainlog.conf'],
      File['/etc/icinga2/features-enabled/notification.conf'],
      File['/etc/icinga2/zones.conf'],
      File['/etc/icinga2/conf.d/api-users.conf'],
      File['/var/lib/icinga2/ca'],
      File['/var/lib/icinga2/ca/ca.key'],
      File['/var/lib/icinga2/ca/ca.crt'],
      File['/etc/icinga2/pki'],
      File['/etc/icinga2/pki/ca.crt'],
      File["/etc/icinga2/pki/${facts['fqdn']}.key"],
      File["/etc/icinga2/pki/${facts['fqdn']}.crt"],
      File["/etc/icinga2/pki/${facts['fqdn']}.csr"],
    ],
  }
}