This repository was archived by the owner on Mar 3, 2023. It is now read-only.
forked from voxpupuli/puppet-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugeas.pp
98 lines (92 loc) · 2.78 KB
/
augeas.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
# == Definition jenkins::augeas
#
# === Parameters:
#
# [*config_filename*]: Filename of the configuration file to work on relative to the jenkins localstatedir.
#
# [*changes*]: String or array with augeas changes to perform.
#
# [*onlyif*]: Optional augeas command and comparisons to control the execution of this type.
#
# [*plugin*]: Optionally jenkins::augeas can also install the plugin. If this is set to true,
# we use the name of the resource as plugin name. If it's a string, that is used
# as plugin name.
#
# [*plugin_version*]: Optional plugin version to pass through to jenkins::plugin
#
# [*context*]: Optional context to ease your change rules.
#
# [*restart*]: If set to true, will trigger a jenkins (safe-)restart in stead of reloading
# the configuration.
#
# === Example:
#
# jenkins::augeas {'git':
# plugin => true,
# config_filename => 'hudson.plugins.git.GitSCM.xml',
# context => '/hudson.plugins.git.GitSCM_-DescriptorImpl',
# changes => [
# 'set globalConfigName/#text "Bob the Builder"',
# 'set globalConfigEmail/#text "[email protected]",
# ],
# }
#
#
#
define jenkins::augeas (
$config_filename,
$changes,
$onlyif = undef,
$context = '/',
$plugin_version = undef,
$plugin = false,
$restart = false,
) {
validate_string($config_filename)
if ! is_string($changes) and ! is_array($changes) {
fail('$changes must be string or array.')
}
if ! is_string($onlyif) and ! is_array($onlyif) {
fail('$onlyif must be string or array.')
}
validate_string($context)
validate_string($plugin_version)
if ! is_bool($plugin) and ! is_string($plugin) {
fail('$plugin must be bool or string.')
}
validate_bool($restart)
include ::jenkins
include ::jenkins::cli
case $plugin {
true: {
jenkins::plugin {$name:
version => $plugin_version,
manage_config => false,
before => Augeas["jenkins::augeas: ${name}"],
}
}
false: {
# do nothing
}
default: {
jenkins::plugin {$plugin:
version => $plugin_version,
manage_config => false,
before => Augeas["jenkins::augeas: ${name}"],
}
}
}
if $restart {
$notify_exec = 'safe-restart-jenkins'
} else {
$notify_exec = 'reload-jenkins'
}
augeas {"jenkins::augeas: ${name}":
incl => "${::jenkins::localstatedir}/${config_filename}",
lens => 'Xml.lns',
context => regsubst("/files${::jenkins::localstatedir}/${config_filename}/${context}", '\/{2,}', '/', 'G'),
notify => Exec[$notify_exec],
onlyif => $onlyif,
changes => $changes,
}
}