forked from basvandervlies/cf_surfsara_lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages.cf
238 lines (196 loc) · 7.89 KB
/
packages.cf
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
#
# SURFsara packages.cf
#
@if minimum_version(99.9)
# packages.cf
Source: [packages.cf](/masterfiles/lib/surfsara/packages.cf)
## sara_service_packages
This bundle handles the service packages. The service bundle defines the default
package(s) to install/remove and/or purge. It can be overriden with json data, eg:
```
"vars": {
"ssh": {
"packages": {
"install": {
"openssh-server": "[version]"
}
}
}
}
```
This will install the 'openssh-server' package and override the package definitions in the service bundle ssh.
The `[version]` can be empty `""`. It will install any version of the package.
Another example is to install and remove ssh packages in 'def.json':
```
"vars": {
"ssh": {
"packages": {
"install": {
"openssh-server": "[version]"
},
"remove": {
"openssh-blacklist": "[version]"
}
}
}
}
```
The following package actions are implemented:
* install: install the package
* install_backports: install the package from backports (Debian)
* purge: delete the package and all it configuration files
* remove: delete the package and preserve the configuration files
@endif
bundle agent sara_service_packages(bundle_name, data)
{
vars:
sara_json_packages_specified::
"pkg_data" data => mergedata("{}", "sara_data.$(bundle_name)[packages]");
"debug_str" string => "Use 'def.json' service package definition";
!sara_json_packages_specified::
"pkg_data" data => mergedata("{}", "data");
"debug_str" string => "Use bundle service packages definition";
any::
"actions" slist => getindices("pkg_data");
"pkg_bundles" slist => maplist("sara_service_packages_$(this)", @(actions));
classes:
"sara_json_packages_specified" expression => isvariable("sara_data.$(bundle_name)[packages]"),
comment => "Do we override the bundle services package with def.json settings";
methods:
"" usebundle => $(pkg_bundles)("$(bundle_name)", "@(sara_service_packages.pkg_data)"),
comment => "package bundle implemented install/remove/purge";
reports:
"$(this.bundle): $(actions): $(debug_str))"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
}
bundle agent sara_service_package(bundle_name, package, version, action, options)
{
classes:
"version_specified" expression => not(strcmp("", "$(version)"));
"options_specified" expression => not(strcmp("", "$(options)"));
vars:
"debug_str" string => ifelse(
"version_specified.options_specified", "version: '$(version)', package_options: '$(options)'",
"version_specified.!options_specified", "version: '$(version)', package_options: 'NA'",
"!version_specified.options_specified", "version: 'NA', package_options: '$(options)'",
"version: 'NA', package_options: 'NA'");
packages:
!version_specified::
"$(package)"
policy => "$(action)",
options => { "$(options)" };
version_specified::
"$(package)"
policy => "$(action)",
version => "$(version)",
options => { "$(options)" };
reports:
any::
"$(this.bundle): $(package):$(action) with $(debug_str)"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
}
bundle agent sara_service_packages_install(bundle_name, pkg_data)
{
vars:
any::
"packages" slist => getindices("pkg_data[install]");
methods:
any::
"" usebundle => sara_service_package("$(bundle_name)",
"$(packages)", "$(pkg_data[install][$(packages)])", "present", "");
}
bundle agent sara_service_packages_install_backports(bundle_name, pkg_data)
{
vars:
any::
"packages" slist => getindices("pkg_data[install_backports]");
@if minimum_version(3.12)
debian::
"release" string => regex_replace("$(sys.os_release[VERSION])", ".*\((\w+).*", "\1", "");
"pkg_options" string => "--target-release=$(release)-backports";
@endif
(!debian|cfengine_3_7|cfengine_3_10)::
"pkg_options" string => "";
methods:
any::
"" usebundle => sara_service_package("$(bundle_name)",
"$(packages)", "$(pkg_data[install_backports][$(packages)])", "present", "$(pkg_options)");
reports:
(cfengine_3_7|cfengine_3_10)::
"$(this.bundle) is not supported on versions lower than CFEngine 3.12, falling back to normal install"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
!debian::
"$(this.bundle) is only supported on Debian, falling back to normal install"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
}
bundle agent sara_service_packages_remove(bundle_name, pkg_data)
{
vars:
any::
"packages" slist => getindices("pkg_data[remove]");
methods:
any::
"" usebundle => sara_service_package("$(bundle_name)",
"$(packages)", "$(pkg_data[remove][$(packages)])", "absent", "");
}
bundle agent sara_service_packages_purge(bundle_name, pkg_data)
{
vars:
any::
"packages" slist => getindices("pkg_data[purge]");
debian::
"pkg_options" string => "--purge";
!debian::
"pkg_options" string => "";
methods:
any::
"" usebundle => sara_service_package("$(bundle_name)",
"$(packages)", "$(pkg_data[purge][$(packages)])", "absent", "$(pkg_options)");
}
###### Obsolete will be deleted
##
bundle agent sara_install_service_packages(bundle_name, default_packages)
{
vars:
"package_data" data => mergedata("{}", "sara_data.$(bundle_name)[packages]"),
ifvarclass => and(
"sara_$(bundle_name)_packages_specified"
);
"package_data" data => mergedata("{}", "default_packages"),
ifvarclass => and(
"!sara_$(bundle_name)_packages_specified"
);
"packages_data_str" string => format("%S", "package_data"),
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
"packages" slist => getindices("package_data");
classes:
"sara_$(bundle_name)_packages_specified" expression => reglist("@(sara_data.$(bundle_name)[packages])", ".*");
#"sara_$(bundle_name)_packages_specified" expression => regarray("@(sara_data.$(bundle_name)[packages])", ".*");
methods:
any::
"" usebundle => sara_install_service_package("$(bundle_name)", "$(packages)", "$(package_data[$(packages)])"),
comment => "Install the package with version";
reports:
"$(this.bundle) packages: $(packages_data_str)"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
}
bundle agent sara_install_service_package(bundle_name, package, version)
{
classes:
"version_specified" expression => not(strcmp("", "$(version)"));
packages:
!version_specified::
"$(package)"
policy => "present";
version_specified::
"$(package)"
policy => "present",
version => "$(version)";
reports:
!version_specified::
"$(this.bundle): Install package: $(package) with version: 'not specified'"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
version_specified::
"$(this.bundle): Install package: '$(package)' with version: '$(version)'"
ifvarclass => "DEBUG_$(bundle_name)|DEBUG|DEBUG_MUSTACHE_JSON|DEBUG_MUSTACHE";
}