summaryrefslogtreecommitdiff
path: root/sitemodules/profiles/manifests/icinga2_master.pp
blob: fb3e13201bc2cfdd2f7a0d5ec56f08fc0e4bca29 (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
# Class: profiles::icinga2_master
# ===============================
#
# This class installs and configures the Icinga2 master with
# PostgreSQL IDO backend
#
# Parameters
# ----------
#
# @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
#
# 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 $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,
) {
  include 'profiles::icinga2_common'

  file { '/var/cache/debconf/icinga2-ido-pgsql.preseed':
    ensure => file,
    source => 'puppet:///modules/profiles/icinga2_master/icinga2-ido-pgsql.preseed',
    owner  => 'root',
    group  => 'root',
    mode   => '0600',
  }
  package { 'icinga2-ido-pgsql':
    ensure       => latest,
    responsefile => '/var/cache/debconf/icinga2-ido-pgsql.preseed',
    require      => [
      Package['icinga2'],
      File['/var/cache/debconf/icinga2-ido-pgsql.preseed'],
    ]
  }
  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/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/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/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 => $::profiles::icinga2_common::ca_certificate,
    owner   => 'nagios',
    group   => 'nagios',
    mode    => '0644',
    require => File['/var/lib/icinga2/ca'],
  }
  exec { "/usr/sbin/icinga2 node setup --master --zone ${::facts['fqdn']} --cn ${::facts['fqdn']}":
    creates => "/var/lib/icinga2/certs/${::facts['fqdn']}.crt",
    require => Package['icinga2'],
    notify  => Service['icinga2'],
  }
  exec { '/usr/sbin/icinga2 feature enable ido-pgsql':
    creates => "/etc/icinga2/features-enabled/ido-pgsql.conf",
    require => Package['icinga2-ido-pgsql'],
    notify  => Service['icinga2'],
  }
  service { 'icinga2':
    ensure    => 'running',
    enable    => true,
    require   => [
      Package['icinga2'],
      Package['icinga2-ido-pgsql'],
    ],
    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/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'],
    ],
  }
}