-
-
Notifications
You must be signed in to change notification settings - Fork 164
/
init.pp
290 lines (270 loc) · 11.2 KB
/
init.pp
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
# @summary Base class for Puppetboard. Sets up the user and python environment.
#
# @param install_from Specify how the app should be installed
# @param user Puppetboard system user.
# @param homedir Puppetboard system user's home directory.
# @param group Puppetboard system group.
# @param groups additional groups for the user that runs puppetboard
# @param basedir Base directory where to build puppetboard vcsrepo and python virtualenv.
# @param git_source Location of upstream Puppetboard GIT repository
# @param puppetdb_host PuppetDB Host
# @param puppetdb_port PuppetDB Port
# @param puppetdb_key path to PuppetMaster/CA signed client SSL key
# @param puppetdb_ssl_verify whether PuppetDB uses SSL or not (true or false), or the path to the puppet CA
# @param puppetdb_cert path to PuppetMaster/CA signed client SSL cert
# @param puppetdb_timeout timeout, in seconds, for connecting to PuppetDB
# @param unresponsive number of hours after which a node is considered "unresponsive"
# @param enable_catalog Whether to allow the user to browser catalog comparisons.
# @param enable_query Whether to allow the user to run raw queries against PuppetDB.
# @param offline_mode Weather to load static assents (jquery, semantic-ui, tablesorter, etc)
# @param localise_timestamp Whether to localise the timestamps in the UI.
# @param python_loglevel Python logging module log level.
# @param python_proxy HTTP proxy server to use for pip/virtualenv.
# @param python_index HTTP index server to use for pip/virtualenv.
# @param python_systempkgs Python system packages available in virtualenv.
# @param default_environment set the default environment
# @param revision Commit, tag, or branch from Puppetboard's Git repo to be used
# @param version PyPI package version to be installed
# @param use_pre_releases if version is set to 'latest', then should pre-releases be used too?
# @param manage_git If true, require the git package. If false do nothing.
# @param manage_virtualenv If true, require the virtualenv package. If false do nothing.
# @param python_version Python version to use in virtualenv.
# @param virtualenv_dir Set location where virtualenv will be installed
# @param manage_user If true, manage (create) this group. If false do nothing.
# @param manage_group If true, manage (create) this group. If false do nothing.
# @param package_name Name of the package to install puppetboard
# @param manage_selinux If true, manage selinux policies for puppetboard. If false do nothing.
# @param reports_count This is the number of reports that we want the dashboard to display.
# @param settings_file Path to puppetboard configuration file
# @param extra_settings Defaults to an empty hash '{}'. Used to pass in arbitrary key/value
# @param override Sets the Apache AllowOverride value
# @param enable_ldap_auth Whether to enable LDAP auth
# @param ldap_require_group LDAP group to require on login
# @param apache_confd path to the apache2 vhost directory
# @param apache_service name of the apache2 service
# @param secret_key used for CSRF prevention and more. It should be a long, secret string, the same for all instances of the app. Required since Puppetboard 5.0.0.
#
# @example
# configure puppetboard with an apache config for a subpath (http://$fqdn/puppetboard)
#
# class { 'puppetboard':
# user => 'pboard',
# group => 'pboard',
# basedir => '/www/puppetboard'
# } ->
# class { 'puppetboard::apache::conf':
# user => 'pboard',
# group => 'pboard',
# basedir => '/www/puppetboard'
# }
#
class puppetboard (
Stdlib::Absolutepath $apache_confd,
String[1] $apache_service,
Python::Version $python_version,
Enum['package', 'pip', 'vcsrepo'] $install_from = 'pip',
Boolean $manage_selinux = pick($facts['os.selinux.enabled'], false),
String $user = 'puppetboard',
Optional[Stdlib::Absolutepath] $homedir = undef,
String $group = 'puppetboard',
Optional[Variant[String[1], Array[String[1]]]] $groups = undef,
Stdlib::AbsolutePath $basedir = '/srv/puppetboard',
String $git_source = 'https://github.com/voxpupuli/puppetboard',
String $puppetdb_host = '127.0.0.1',
Stdlib::Port $puppetdb_port = 8080,
Optional[Stdlib::AbsolutePath] $puppetdb_key = undef,
Variant[Boolean, Stdlib::AbsolutePath] $puppetdb_ssl_verify = false,
Optional[Stdlib::AbsolutePath] $puppetdb_cert = undef,
Integer[0] $puppetdb_timeout = 20,
Integer[0] $unresponsive = 3,
Boolean $enable_catalog = false,
Boolean $enable_query = true,
Boolean $localise_timestamp = true,
Puppetboard::Syslogpriority $python_loglevel = 'info',
Optional[String[1]] $python_proxy = undef,
Optional[String[1]] $python_index = undef,
Boolean $python_systempkgs = false,
Optional[String] $revision = undef,
Boolean $manage_user = true,
Boolean $manage_group = true,
Optional[String[1]] $package_name = undef,
Boolean $manage_git = false,
Boolean $manage_virtualenv = false,
Stdlib::Absolutepath $virtualenv_dir = "${basedir}/virtenv-puppetboard",
Integer[0] $reports_count = 10,
String[1] $default_environment = 'production',
Boolean $offline_mode = false,
Stdlib::Absolutepath $settings_file = "${basedir}/puppetboard/settings.py",
Hash $extra_settings = {},
Variant[Array[String[1]], String[1]] $override = ['None'],
Boolean $enable_ldap_auth = false,
Boolean $ldap_require_group = false,
Variant[Enum['latest'], String[1]] $version = 'latest',
Boolean $use_pre_releases = false,
Optional[String[1]] $secret_key = undef,
) {
if !$secret_key {
$message = join([
"Starting with Puppetboard 5.0.0 providing own \$secret_key is required.",
'See https://github.com/voxpupuli/puppetboard/issues/721 for more info.',
'If you run Puppetboard on a single node with static FQDN then you can set it the following code',
"to generate a random but not changing value: \${fqdn_rand_string(32)}",
], ' ')
if $version == 'latest' or versioncmp($version, '5.0.0') >= 0 {
fail($message)
} else {
notify { 'Warning':
message => $message,
}
}
}
if $manage_group {
group { $group:
ensure => present,
system => true,
}
}
if $manage_user {
user { $user:
ensure => present,
shell => '/bin/sh',
home => $homedir,
managehome => true,
gid => $group,
system => true,
groups => $groups,
require => Group[$group],
}
}
$pyvenv_proxy_env = $python_proxy ? {
undef => [],
default => [
"HTTP_PROXY=${python_proxy}",
"HTTPS_PROXY=${python_proxy}",
]
}
if $install_from in ['pip', 'vcsrepo'] {
file { $basedir:
ensure => 'directory',
owner => $user,
group => $group,
mode => '0755',
}
}
case $install_from {
'package': {
package { $package_name:
ensure => installed,
}
}
'pip': {
if $revision {
fail("'pip' installation method uses \$version parameter to specify version, not \$revision.")
}
file { "${basedir}/puppetboard":
ensure => directory,
recurse => true,
force => true,
purge => true, # such cleanup is needed in case of a switch from install_from=vcsrepo to install_from=pip
}
python::pyvenv { $virtualenv_dir:
ensure => present,
version => $python_version,
systempkgs => $python_systempkgs,
owner => $user,
group => $group,
require => File[$basedir],
environment => $pyvenv_proxy_env,
}
$install_args = $use_pre_releases ? {
true => '--pre',
default => undef,
}
python::pip { 'puppetboard':
ensure => $version,
virtualenv => $virtualenv_dir,
proxy => $python_proxy,
owner => $user,
group => $group,
require => Python::Pyvenv[$virtualenv_dir],
install_args => $install_args,
}
}
'vcsrepo': {
if $version != 'latest' {
fail("'vcsrepo' installation method uses \$revision parameter to specify version, not \$version.")
}
notify { 'Not recommended':
message => "This installation method is recommended mainly for the contributors to voxpupuli/puppetboard.
Consider switching to 'pip' if you are not one of them.",
}
vcsrepo { "${basedir}/puppetboard":
ensure => present,
provider => git,
user => $user,
source => $git_source,
revision => $revision,
require => [
User[$user],
Group[$group],
],
before => [
File[$settings_file],
],
notify => Python::Requirements["${basedir}/puppetboard/requirements.txt"],
}
python::pyvenv { $virtualenv_dir:
ensure => present,
version => $python_version,
systempkgs => false,
owner => $user,
group => $group,
require => Vcsrepo["${basedir}/puppetboard"],
environment => $pyvenv_proxy_env,
}
python::requirements { "${basedir}/puppetboard/requirements.txt":
virtualenv => $virtualenv_dir,
proxy => $python_proxy,
owner => $user,
group => $group,
}
}
default: {
fail("Unsupported installation method: ${install_from}")
}
}
file { $settings_file:
ensure => 'file',
group => $group,
mode => '0644',
owner => $user,
content => template('puppetboard/settings.py.erb'),
}
if $manage_git and !defined(Package['git']) {
package { 'git':
ensure => installed,
}
}
if $manage_virtualenv {
class { 'python':
version => $python_version,
dev => 'present',
venv => 'present',
}
Class['python'] -> Class['puppetboard']
}
if $manage_selinux {
selboolean { 'httpd_can_network_relay':
persistent => true,
value => 'on',
}
selboolean { 'httpd_can_network_connect':
persistent => true,
value => 'on',
}
selboolean { 'httpd_can_network_connect_db':
persistent => true,
value => 'on',
}
}
}