chef-utils 18.0.169 → 18.0.172
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/Rakefile +15 -15
- data/chef-utils.gemspec +50 -50
- data/lib/chef-utils/dist.rb +154 -154
- data/lib/chef-utils/dsl/architecture.rb +150 -150
- data/lib/chef-utils/dsl/cloud.rb +155 -155
- data/lib/chef-utils/dsl/default_paths.rb +60 -60
- data/lib/chef-utils/dsl/introspection.rb +134 -134
- data/lib/chef-utils/dsl/os.rb +58 -58
- data/lib/chef-utils/dsl/path_sanity.rb +39 -39
- data/lib/chef-utils/dsl/platform.rb +387 -387
- data/lib/chef-utils/dsl/platform_family.rb +360 -360
- data/lib/chef-utils/dsl/platform_version.rb +41 -41
- data/lib/chef-utils/dsl/service.rb +112 -112
- data/lib/chef-utils/dsl/train_helpers.rb +87 -87
- data/lib/chef-utils/dsl/virtualization.rb +272 -272
- data/lib/chef-utils/dsl/which.rb +123 -123
- data/lib/chef-utils/dsl/windows.rb +86 -86
- data/lib/chef-utils/internal.rb +114 -114
- data/lib/chef-utils/mash.rb +263 -263
- data/lib/chef-utils/parallel_map.rb +131 -131
- data/lib/chef-utils/version.rb +20 -20
- data/lib/chef-utils/version_string.rb +160 -160
- data/lib/chef-utils.rb +53 -53
- data/spec/spec_helper.rb +100 -100
- data/spec/unit/dsl/architecture_spec.rb +151 -151
- data/spec/unit/dsl/cloud_spec.rb +93 -93
- data/spec/unit/dsl/dsl_spec.rb +34 -34
- data/spec/unit/dsl/introspection_spec.rb +201 -201
- data/spec/unit/dsl/os_spec.rb +175 -175
- data/spec/unit/dsl/path_sanity_spec.rb +86 -86
- data/spec/unit/dsl/platform_family_spec.rb +235 -235
- data/spec/unit/dsl/platform_spec.rb +252 -252
- data/spec/unit/dsl/service_spec.rb +117 -117
- data/spec/unit/dsl/virtualization_spec.rb +75 -75
- data/spec/unit/dsl/which_spec.rb +171 -171
- data/spec/unit/dsl/windows_spec.rb +84 -84
- data/spec/unit/mash_spec.rb +51 -51
- data/spec/unit/parallel_map_spec.rb +156 -156
- metadata +7 -7
@@ -1,360 +1,360 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require_relative "../internal"
|
20
|
-
|
21
|
-
module ChefUtils
|
22
|
-
module DSL
|
23
|
-
module PlatformFamily
|
24
|
-
include Internal
|
25
|
-
|
26
|
-
# Determine if the current node is a member of the 'arch' family.
|
27
|
-
#
|
28
|
-
# @param [Chef::Node] node the node to check
|
29
|
-
# @since 15.5
|
30
|
-
#
|
31
|
-
# @return [Boolean]
|
32
|
-
#
|
33
|
-
def arch?(node = __getnode)
|
34
|
-
node["platform_family"] == "arch"
|
35
|
-
end
|
36
|
-
# chef-sugar backcompat method
|
37
|
-
alias_method :arch_linux?, :arch?
|
38
|
-
|
39
|
-
# Determine if the current node is a member of the 'aix' platform family.
|
40
|
-
#
|
41
|
-
# @param [Chef::Node] node the node to check
|
42
|
-
# @since 15.5
|
43
|
-
#
|
44
|
-
# @return [Boolean]
|
45
|
-
#
|
46
|
-
def aix?(node = __getnode)
|
47
|
-
node["platform_family"] == "aix"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Determine if the current node is a member of the 'debian' platform family (Debian, Ubuntu and derivatives).
|
51
|
-
#
|
52
|
-
# @param [Chef::Node] node the node to check
|
53
|
-
# @since 15.5
|
54
|
-
#
|
55
|
-
# @return [Boolean]
|
56
|
-
#
|
57
|
-
def debian?(node = __getnode)
|
58
|
-
node["platform_family"] == "debian"
|
59
|
-
end
|
60
|
-
|
61
|
-
# Determine if the current node is a member of the 'fedora' platform family (Fedora and Arista).
|
62
|
-
#
|
63
|
-
# @param [Chef::Node] node the node to check
|
64
|
-
# @since 15.5
|
65
|
-
#
|
66
|
-
# @return [Boolean]
|
67
|
-
#
|
68
|
-
def fedora?(node = __getnode)
|
69
|
-
node["platform_family"] == "fedora"
|
70
|
-
end
|
71
|
-
|
72
|
-
# Determine if the current node is a member of the 'mac_os_x' platform family.
|
73
|
-
#
|
74
|
-
# @param [Chef::Node] node the node to check
|
75
|
-
# @since 15.5
|
76
|
-
#
|
77
|
-
# @return [Boolean]
|
78
|
-
#
|
79
|
-
def macos?(node = __getnode)
|
80
|
-
node ? node["platform_family"] == "mac_os_x" : macos_ruby?
|
81
|
-
end
|
82
|
-
# chef-sugar backcompat method
|
83
|
-
alias_method :osx?, :macos?
|
84
|
-
# chef-sugar backcompat method
|
85
|
-
alias_method :mac?, :macos?
|
86
|
-
# chef-sugar backcompat method
|
87
|
-
alias_method :mac_os_x?, :macos?
|
88
|
-
|
89
|
-
# Determine if the Ruby VM is currently running on a Mac node (This is useful primarily for internal use
|
90
|
-
# by Chef Infra Client before the node object exists).
|
91
|
-
#
|
92
|
-
# @since 17.3
|
93
|
-
#
|
94
|
-
# @return [Boolean]
|
95
|
-
#
|
96
|
-
def macos_ruby?
|
97
|
-
!!(RUBY_PLATFORM =~ /darwin/)
|
98
|
-
end
|
99
|
-
|
100
|
-
# Determine if the current node is a member of the 'rhel' platform family (Red Hat, CentOS, Oracle or Scientific Linux, but NOT Amazon Linux or Fedora).
|
101
|
-
#
|
102
|
-
# @param [Chef::Node] node the node to check
|
103
|
-
# @since 15.5
|
104
|
-
#
|
105
|
-
# @return [Boolean]
|
106
|
-
#
|
107
|
-
def rhel?(node = __getnode)
|
108
|
-
node["platform_family"] == "rhel"
|
109
|
-
end
|
110
|
-
# chef-sugar backcompat method
|
111
|
-
alias_method :el?, :rhel?
|
112
|
-
|
113
|
-
# Determine if the current node is a rhel6 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
|
114
|
-
#
|
115
|
-
# @param [Chef::Node] node the node to check
|
116
|
-
# @since 15.5
|
117
|
-
#
|
118
|
-
# @return [Boolean]
|
119
|
-
#
|
120
|
-
def rhel6?(node = __getnode)
|
121
|
-
node["platform_family"] == "rhel" && node["platform_version"].to_f >= 6.0 && node["platform_version"].to_f < 7.0
|
122
|
-
end
|
123
|
-
|
124
|
-
# Determine if the current node is a rhel7 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
|
125
|
-
#
|
126
|
-
# @param [Chef::Node] node the node to check
|
127
|
-
# @since 15.5
|
128
|
-
#
|
129
|
-
# @return [Boolean]
|
130
|
-
#
|
131
|
-
def rhel7?(node = __getnode)
|
132
|
-
node["platform_family"] == "rhel" && node["platform_version"].to_f >= 7.0 && node["platform_version"].to_f < 8.0
|
133
|
-
end
|
134
|
-
|
135
|
-
# Determine if the current node is a rhel8 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
|
136
|
-
#
|
137
|
-
# @param [Chef::Node] node the node to check
|
138
|
-
# @since 15.5
|
139
|
-
#
|
140
|
-
# @return [Boolean]
|
141
|
-
#
|
142
|
-
def rhel8?(node = __getnode)
|
143
|
-
node["platform_family"] == "rhel" && node["platform_version"].to_f >= 8.0 && node["platform_version"].to_f < 9.0
|
144
|
-
end
|
145
|
-
|
146
|
-
# Determine if the current node is a member of the 'amazon' platform family.
|
147
|
-
#
|
148
|
-
# @param [Chef::Node] node the node to check
|
149
|
-
# @since 15.5
|
150
|
-
#
|
151
|
-
# @return [Boolean]
|
152
|
-
#
|
153
|
-
def amazon?(node = __getnode)
|
154
|
-
node["platform_family"] == "amazon"
|
155
|
-
end
|
156
|
-
# chef-sugar backcompat method
|
157
|
-
alias_method :amazon_linux?, :amazon?
|
158
|
-
|
159
|
-
# Determine if the current node is a member of the 'solaris2' platform family.
|
160
|
-
#
|
161
|
-
# @param [Chef::Node] node the node to check
|
162
|
-
# @since 15.5
|
163
|
-
#
|
164
|
-
# @return [Boolean]
|
165
|
-
#
|
166
|
-
def solaris2?(node = __getnode)
|
167
|
-
node["platform_family"] == "solaris2"
|
168
|
-
end
|
169
|
-
# chef-sugar backcompat method
|
170
|
-
alias_method :solaris?, :solaris2?
|
171
|
-
|
172
|
-
# Determine if the current node is a member of the 'smartos' platform family.
|
173
|
-
#
|
174
|
-
# @param [Chef::Node] node the node to check
|
175
|
-
# @since 15.5
|
176
|
-
#
|
177
|
-
# @return [Boolean]
|
178
|
-
#
|
179
|
-
def smartos?(node = __getnode)
|
180
|
-
node["platform_family"] == "smartos"
|
181
|
-
end
|
182
|
-
|
183
|
-
# Determine if the current node is a member of the 'suse' platform family (openSUSE, SLES, and SLED).
|
184
|
-
#
|
185
|
-
# @param [Chef::Node] node the node to check
|
186
|
-
# @since 15.5
|
187
|
-
#
|
188
|
-
# @return [Boolean]
|
189
|
-
#
|
190
|
-
def suse?(node = __getnode)
|
191
|
-
node["platform_family"] == "suse"
|
192
|
-
end
|
193
|
-
|
194
|
-
# Determine if the current node is a member of the 'gentoo' platform family.
|
195
|
-
#
|
196
|
-
# @param [Chef::Node] node the node to check
|
197
|
-
# @since 15.5
|
198
|
-
#
|
199
|
-
# @return [Boolean]
|
200
|
-
#
|
201
|
-
def gentoo?(node = __getnode)
|
202
|
-
node["platform_family"] == "gentoo"
|
203
|
-
end
|
204
|
-
|
205
|
-
# Determine if the current node is a member of the 'freebsd' platform family.
|
206
|
-
#
|
207
|
-
# @param [Chef::Node] node the node to check
|
208
|
-
# @since 15.5
|
209
|
-
#
|
210
|
-
# @return [Boolean]
|
211
|
-
#
|
212
|
-
def freebsd?(node = __getnode)
|
213
|
-
node["platform_family"] == "freebsd"
|
214
|
-
end
|
215
|
-
|
216
|
-
# Determine if the current node is a member of the 'openbsd' platform family.
|
217
|
-
#
|
218
|
-
# @param [Chef::Node] node the node to check
|
219
|
-
# @since 15.5
|
220
|
-
#
|
221
|
-
# @return [Boolean]
|
222
|
-
#
|
223
|
-
def openbsd?(node = __getnode)
|
224
|
-
node["platform_family"] == "openbsd"
|
225
|
-
end
|
226
|
-
|
227
|
-
# Determine if the current node is a member of the 'netbsd' platform family.
|
228
|
-
#
|
229
|
-
# @param [Chef::Node] node the node to check
|
230
|
-
# @since 15.5
|
231
|
-
#
|
232
|
-
# @return [Boolean]
|
233
|
-
#
|
234
|
-
def netbsd?(node = __getnode)
|
235
|
-
node["platform_family"] == "netbsd"
|
236
|
-
end
|
237
|
-
|
238
|
-
# Determine if the current node is a member of the 'dragonflybsd' platform family.
|
239
|
-
#
|
240
|
-
# @param [Chef::Node] node the node to check
|
241
|
-
# @since 15.5
|
242
|
-
#
|
243
|
-
# @return [Boolean]
|
244
|
-
#
|
245
|
-
def dragonflybsd?(node = __getnode)
|
246
|
-
node["platform_family"] == "dragonflybsd"
|
247
|
-
end
|
248
|
-
|
249
|
-
# Determine if the current node is a member of the 'windows' platform family.
|
250
|
-
#
|
251
|
-
# @param [Chef::Node] node the node to check
|
252
|
-
# @since 15.5
|
253
|
-
#
|
254
|
-
# @return [Boolean]
|
255
|
-
#
|
256
|
-
def windows?(node = __getnode(true))
|
257
|
-
# This is all somewhat complicated. We prefer to get the node object so that chefspec can
|
258
|
-
# stub the node object. But we also have to deal with class-parsing time where there is
|
259
|
-
# no node object, so we have to fall back to RUBY_PLATFORM based detection. We cannot pull
|
260
|
-
# the node object out of the Chef.run_context.node global object here (which is what the
|
261
|
-
# false flag to __getnode is about) because some run-time code also cannot run under chefspec
|
262
|
-
# on non-windows where the node is stubbed to windows.
|
263
|
-
#
|
264
|
-
# As a result of this the `windows?` helper and the `ChefUtils.windows?` helper do not behave
|
265
|
-
# the same way in that the latter is not stubbable by chefspec.
|
266
|
-
#
|
267
|
-
node ? node["platform_family"] == "windows" : windows_ruby?
|
268
|
-
end
|
269
|
-
|
270
|
-
# Determine if the Ruby VM is currently running on a Windows node (ChefSpec can never stub
|
271
|
-
# this behavior, so this is useful for code which can never be parsed on a non-Windows box).
|
272
|
-
#
|
273
|
-
# April 2022 - Note that we changed the platform identifier from 'mingw32' to 'mingw'
|
274
|
-
# We did this because Ruby 3.1 introduces the new universal windows platform of 'x64-mingw-ucrt'
|
275
|
-
# We updated the existing regex snippet to capture both the 32-bit platform and the new x64
|
276
|
-
# universal platform
|
277
|
-
#
|
278
|
-
# @since 15.5
|
279
|
-
#
|
280
|
-
# @return [Boolean]
|
281
|
-
#
|
282
|
-
def windows_ruby?
|
283
|
-
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
284
|
-
end
|
285
|
-
|
286
|
-
#
|
287
|
-
# Platform-Family-like Helpers
|
288
|
-
#
|
289
|
-
# These are meta-helpers which address the issue that platform_family is single valued and cannot
|
290
|
-
# be an array while a tree-like Taxonomy is what is called for in some cases.
|
291
|
-
#
|
292
|
-
|
293
|
-
# If it uses RPM, it goes in here (rhel, fedora, amazon, suse platform_families). Deliberately does not
|
294
|
-
# include AIX because bff is AIX's primary package manager and adding it here would make this substantially
|
295
|
-
# less useful since in no way can AIX trace its lineage back to old redhat distros. This is most useful for
|
296
|
-
# "smells like redhat, including SuSE".
|
297
|
-
#
|
298
|
-
# @param [Chef::Node] node the node to check
|
299
|
-
# @since 15.5
|
300
|
-
#
|
301
|
-
# @return [Boolean]
|
302
|
-
#
|
303
|
-
def rpm_based?(node = __getnode)
|
304
|
-
fedora_derived?(node) || node["platform_family"] == "suse"
|
305
|
-
end
|
306
|
-
|
307
|
-
# RPM-based distros which are not SuSE and are very loosely similar to fedora, using yum or dnf. The historical
|
308
|
-
# lineage of the distro should have forked off from old redhat fedora distros at some point. Currently rhel,
|
309
|
-
# fedora and amazon. This is most useful for "smells like redhat, but isn't SuSE".
|
310
|
-
#
|
311
|
-
# @param [Chef::Node] node the node to check
|
312
|
-
# @since 15.5
|
313
|
-
#
|
314
|
-
# @return [Boolean]
|
315
|
-
#
|
316
|
-
def fedora_derived?(node = __getnode)
|
317
|
-
redhat_based?(node) || node["platform_family"] == "amazon"
|
318
|
-
end
|
319
|
-
|
320
|
-
# RedHat distros -- fedora and rhel platform_families, nothing else. This is most likely not as useful as the
|
321
|
-
# "fedora_derived?" helper.
|
322
|
-
#
|
323
|
-
# @param [Chef::Node] node the node to check
|
324
|
-
# @since 15.5
|
325
|
-
#
|
326
|
-
# @return [Boolean]
|
327
|
-
#
|
328
|
-
def redhat_based?(node = __getnode)
|
329
|
-
%w{rhel fedora}.include?(node["platform_family"])
|
330
|
-
end
|
331
|
-
|
332
|
-
# All of the Solaris-lineage.
|
333
|
-
#
|
334
|
-
# @param [Chef::Node] node the node to check
|
335
|
-
# @since 15.5
|
336
|
-
#
|
337
|
-
# @return [Boolean]
|
338
|
-
#
|
339
|
-
def solaris_based?(node = __getnode)
|
340
|
-
%w{solaris2 smartos omnios openindiana}.include?(node["platform"])
|
341
|
-
end
|
342
|
-
|
343
|
-
# All of the BSD-lineage.
|
344
|
-
#
|
345
|
-
# Note that macOS is not included since macOS deviates so significantly from BSD that including it would not be useful.
|
346
|
-
#
|
347
|
-
# @param [Chef::Node] node the node to check
|
348
|
-
# @since 15.5
|
349
|
-
#
|
350
|
-
# @return [Boolean]
|
351
|
-
#
|
352
|
-
def bsd_based?(node = __getnode)
|
353
|
-
# we could use os, platform_family or platform here equally
|
354
|
-
%w{netbsd freebsd openbsd dragonflybsd}.include?(node["platform"])
|
355
|
-
end
|
356
|
-
|
357
|
-
extend self
|
358
|
-
end
|
359
|
-
end
|
360
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require_relative "../internal"
|
20
|
+
|
21
|
+
module ChefUtils
|
22
|
+
module DSL
|
23
|
+
module PlatformFamily
|
24
|
+
include Internal
|
25
|
+
|
26
|
+
# Determine if the current node is a member of the 'arch' family.
|
27
|
+
#
|
28
|
+
# @param [Chef::Node] node the node to check
|
29
|
+
# @since 15.5
|
30
|
+
#
|
31
|
+
# @return [Boolean]
|
32
|
+
#
|
33
|
+
def arch?(node = __getnode)
|
34
|
+
node["platform_family"] == "arch"
|
35
|
+
end
|
36
|
+
# chef-sugar backcompat method
|
37
|
+
alias_method :arch_linux?, :arch?
|
38
|
+
|
39
|
+
# Determine if the current node is a member of the 'aix' platform family.
|
40
|
+
#
|
41
|
+
# @param [Chef::Node] node the node to check
|
42
|
+
# @since 15.5
|
43
|
+
#
|
44
|
+
# @return [Boolean]
|
45
|
+
#
|
46
|
+
def aix?(node = __getnode)
|
47
|
+
node["platform_family"] == "aix"
|
48
|
+
end
|
49
|
+
|
50
|
+
# Determine if the current node is a member of the 'debian' platform family (Debian, Ubuntu and derivatives).
|
51
|
+
#
|
52
|
+
# @param [Chef::Node] node the node to check
|
53
|
+
# @since 15.5
|
54
|
+
#
|
55
|
+
# @return [Boolean]
|
56
|
+
#
|
57
|
+
def debian?(node = __getnode)
|
58
|
+
node["platform_family"] == "debian"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Determine if the current node is a member of the 'fedora' platform family (Fedora and Arista).
|
62
|
+
#
|
63
|
+
# @param [Chef::Node] node the node to check
|
64
|
+
# @since 15.5
|
65
|
+
#
|
66
|
+
# @return [Boolean]
|
67
|
+
#
|
68
|
+
def fedora?(node = __getnode)
|
69
|
+
node["platform_family"] == "fedora"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Determine if the current node is a member of the 'mac_os_x' platform family.
|
73
|
+
#
|
74
|
+
# @param [Chef::Node] node the node to check
|
75
|
+
# @since 15.5
|
76
|
+
#
|
77
|
+
# @return [Boolean]
|
78
|
+
#
|
79
|
+
def macos?(node = __getnode)
|
80
|
+
node ? node["platform_family"] == "mac_os_x" : macos_ruby?
|
81
|
+
end
|
82
|
+
# chef-sugar backcompat method
|
83
|
+
alias_method :osx?, :macos?
|
84
|
+
# chef-sugar backcompat method
|
85
|
+
alias_method :mac?, :macos?
|
86
|
+
# chef-sugar backcompat method
|
87
|
+
alias_method :mac_os_x?, :macos?
|
88
|
+
|
89
|
+
# Determine if the Ruby VM is currently running on a Mac node (This is useful primarily for internal use
|
90
|
+
# by Chef Infra Client before the node object exists).
|
91
|
+
#
|
92
|
+
# @since 17.3
|
93
|
+
#
|
94
|
+
# @return [Boolean]
|
95
|
+
#
|
96
|
+
def macos_ruby?
|
97
|
+
!!(RUBY_PLATFORM =~ /darwin/)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Determine if the current node is a member of the 'rhel' platform family (Red Hat, CentOS, Oracle or Scientific Linux, but NOT Amazon Linux or Fedora).
|
101
|
+
#
|
102
|
+
# @param [Chef::Node] node the node to check
|
103
|
+
# @since 15.5
|
104
|
+
#
|
105
|
+
# @return [Boolean]
|
106
|
+
#
|
107
|
+
def rhel?(node = __getnode)
|
108
|
+
node["platform_family"] == "rhel"
|
109
|
+
end
|
110
|
+
# chef-sugar backcompat method
|
111
|
+
alias_method :el?, :rhel?
|
112
|
+
|
113
|
+
# Determine if the current node is a rhel6 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
|
114
|
+
#
|
115
|
+
# @param [Chef::Node] node the node to check
|
116
|
+
# @since 15.5
|
117
|
+
#
|
118
|
+
# @return [Boolean]
|
119
|
+
#
|
120
|
+
def rhel6?(node = __getnode)
|
121
|
+
node["platform_family"] == "rhel" && node["platform_version"].to_f >= 6.0 && node["platform_version"].to_f < 7.0
|
122
|
+
end
|
123
|
+
|
124
|
+
# Determine if the current node is a rhel7 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
|
125
|
+
#
|
126
|
+
# @param [Chef::Node] node the node to check
|
127
|
+
# @since 15.5
|
128
|
+
#
|
129
|
+
# @return [Boolean]
|
130
|
+
#
|
131
|
+
def rhel7?(node = __getnode)
|
132
|
+
node["platform_family"] == "rhel" && node["platform_version"].to_f >= 7.0 && node["platform_version"].to_f < 8.0
|
133
|
+
end
|
134
|
+
|
135
|
+
# Determine if the current node is a rhel8 compatible build (Red Hat, CentOS, Oracle or Scientific Linux).
|
136
|
+
#
|
137
|
+
# @param [Chef::Node] node the node to check
|
138
|
+
# @since 15.5
|
139
|
+
#
|
140
|
+
# @return [Boolean]
|
141
|
+
#
|
142
|
+
def rhel8?(node = __getnode)
|
143
|
+
node["platform_family"] == "rhel" && node["platform_version"].to_f >= 8.0 && node["platform_version"].to_f < 9.0
|
144
|
+
end
|
145
|
+
|
146
|
+
# Determine if the current node is a member of the 'amazon' platform family.
|
147
|
+
#
|
148
|
+
# @param [Chef::Node] node the node to check
|
149
|
+
# @since 15.5
|
150
|
+
#
|
151
|
+
# @return [Boolean]
|
152
|
+
#
|
153
|
+
def amazon?(node = __getnode)
|
154
|
+
node["platform_family"] == "amazon"
|
155
|
+
end
|
156
|
+
# chef-sugar backcompat method
|
157
|
+
alias_method :amazon_linux?, :amazon?
|
158
|
+
|
159
|
+
# Determine if the current node is a member of the 'solaris2' platform family.
|
160
|
+
#
|
161
|
+
# @param [Chef::Node] node the node to check
|
162
|
+
# @since 15.5
|
163
|
+
#
|
164
|
+
# @return [Boolean]
|
165
|
+
#
|
166
|
+
def solaris2?(node = __getnode)
|
167
|
+
node["platform_family"] == "solaris2"
|
168
|
+
end
|
169
|
+
# chef-sugar backcompat method
|
170
|
+
alias_method :solaris?, :solaris2?
|
171
|
+
|
172
|
+
# Determine if the current node is a member of the 'smartos' platform family.
|
173
|
+
#
|
174
|
+
# @param [Chef::Node] node the node to check
|
175
|
+
# @since 15.5
|
176
|
+
#
|
177
|
+
# @return [Boolean]
|
178
|
+
#
|
179
|
+
def smartos?(node = __getnode)
|
180
|
+
node["platform_family"] == "smartos"
|
181
|
+
end
|
182
|
+
|
183
|
+
# Determine if the current node is a member of the 'suse' platform family (openSUSE, SLES, and SLED).
|
184
|
+
#
|
185
|
+
# @param [Chef::Node] node the node to check
|
186
|
+
# @since 15.5
|
187
|
+
#
|
188
|
+
# @return [Boolean]
|
189
|
+
#
|
190
|
+
def suse?(node = __getnode)
|
191
|
+
node["platform_family"] == "suse"
|
192
|
+
end
|
193
|
+
|
194
|
+
# Determine if the current node is a member of the 'gentoo' platform family.
|
195
|
+
#
|
196
|
+
# @param [Chef::Node] node the node to check
|
197
|
+
# @since 15.5
|
198
|
+
#
|
199
|
+
# @return [Boolean]
|
200
|
+
#
|
201
|
+
def gentoo?(node = __getnode)
|
202
|
+
node["platform_family"] == "gentoo"
|
203
|
+
end
|
204
|
+
|
205
|
+
# Determine if the current node is a member of the 'freebsd' platform family.
|
206
|
+
#
|
207
|
+
# @param [Chef::Node] node the node to check
|
208
|
+
# @since 15.5
|
209
|
+
#
|
210
|
+
# @return [Boolean]
|
211
|
+
#
|
212
|
+
def freebsd?(node = __getnode)
|
213
|
+
node["platform_family"] == "freebsd"
|
214
|
+
end
|
215
|
+
|
216
|
+
# Determine if the current node is a member of the 'openbsd' platform family.
|
217
|
+
#
|
218
|
+
# @param [Chef::Node] node the node to check
|
219
|
+
# @since 15.5
|
220
|
+
#
|
221
|
+
# @return [Boolean]
|
222
|
+
#
|
223
|
+
def openbsd?(node = __getnode)
|
224
|
+
node["platform_family"] == "openbsd"
|
225
|
+
end
|
226
|
+
|
227
|
+
# Determine if the current node is a member of the 'netbsd' platform family.
|
228
|
+
#
|
229
|
+
# @param [Chef::Node] node the node to check
|
230
|
+
# @since 15.5
|
231
|
+
#
|
232
|
+
# @return [Boolean]
|
233
|
+
#
|
234
|
+
def netbsd?(node = __getnode)
|
235
|
+
node["platform_family"] == "netbsd"
|
236
|
+
end
|
237
|
+
|
238
|
+
# Determine if the current node is a member of the 'dragonflybsd' platform family.
|
239
|
+
#
|
240
|
+
# @param [Chef::Node] node the node to check
|
241
|
+
# @since 15.5
|
242
|
+
#
|
243
|
+
# @return [Boolean]
|
244
|
+
#
|
245
|
+
def dragonflybsd?(node = __getnode)
|
246
|
+
node["platform_family"] == "dragonflybsd"
|
247
|
+
end
|
248
|
+
|
249
|
+
# Determine if the current node is a member of the 'windows' platform family.
|
250
|
+
#
|
251
|
+
# @param [Chef::Node] node the node to check
|
252
|
+
# @since 15.5
|
253
|
+
#
|
254
|
+
# @return [Boolean]
|
255
|
+
#
|
256
|
+
def windows?(node = __getnode(true))
|
257
|
+
# This is all somewhat complicated. We prefer to get the node object so that chefspec can
|
258
|
+
# stub the node object. But we also have to deal with class-parsing time where there is
|
259
|
+
# no node object, so we have to fall back to RUBY_PLATFORM based detection. We cannot pull
|
260
|
+
# the node object out of the Chef.run_context.node global object here (which is what the
|
261
|
+
# false flag to __getnode is about) because some run-time code also cannot run under chefspec
|
262
|
+
# on non-windows where the node is stubbed to windows.
|
263
|
+
#
|
264
|
+
# As a result of this the `windows?` helper and the `ChefUtils.windows?` helper do not behave
|
265
|
+
# the same way in that the latter is not stubbable by chefspec.
|
266
|
+
#
|
267
|
+
node ? node["platform_family"] == "windows" : windows_ruby?
|
268
|
+
end
|
269
|
+
|
270
|
+
# Determine if the Ruby VM is currently running on a Windows node (ChefSpec can never stub
|
271
|
+
# this behavior, so this is useful for code which can never be parsed on a non-Windows box).
|
272
|
+
#
|
273
|
+
# April 2022 - Note that we changed the platform identifier from 'mingw32' to 'mingw'
|
274
|
+
# We did this because Ruby 3.1 introduces the new universal windows platform of 'x64-mingw-ucrt'
|
275
|
+
# We updated the existing regex snippet to capture both the 32-bit platform and the new x64
|
276
|
+
# universal platform
|
277
|
+
#
|
278
|
+
# @since 15.5
|
279
|
+
#
|
280
|
+
# @return [Boolean]
|
281
|
+
#
|
282
|
+
def windows_ruby?
|
283
|
+
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
284
|
+
end
|
285
|
+
|
286
|
+
#
|
287
|
+
# Platform-Family-like Helpers
|
288
|
+
#
|
289
|
+
# These are meta-helpers which address the issue that platform_family is single valued and cannot
|
290
|
+
# be an array while a tree-like Taxonomy is what is called for in some cases.
|
291
|
+
#
|
292
|
+
|
293
|
+
# If it uses RPM, it goes in here (rhel, fedora, amazon, suse platform_families). Deliberately does not
|
294
|
+
# include AIX because bff is AIX's primary package manager and adding it here would make this substantially
|
295
|
+
# less useful since in no way can AIX trace its lineage back to old redhat distros. This is most useful for
|
296
|
+
# "smells like redhat, including SuSE".
|
297
|
+
#
|
298
|
+
# @param [Chef::Node] node the node to check
|
299
|
+
# @since 15.5
|
300
|
+
#
|
301
|
+
# @return [Boolean]
|
302
|
+
#
|
303
|
+
def rpm_based?(node = __getnode)
|
304
|
+
fedora_derived?(node) || node["platform_family"] == "suse"
|
305
|
+
end
|
306
|
+
|
307
|
+
# RPM-based distros which are not SuSE and are very loosely similar to fedora, using yum or dnf. The historical
|
308
|
+
# lineage of the distro should have forked off from old redhat fedora distros at some point. Currently rhel,
|
309
|
+
# fedora and amazon. This is most useful for "smells like redhat, but isn't SuSE".
|
310
|
+
#
|
311
|
+
# @param [Chef::Node] node the node to check
|
312
|
+
# @since 15.5
|
313
|
+
#
|
314
|
+
# @return [Boolean]
|
315
|
+
#
|
316
|
+
def fedora_derived?(node = __getnode)
|
317
|
+
redhat_based?(node) || node["platform_family"] == "amazon"
|
318
|
+
end
|
319
|
+
|
320
|
+
# RedHat distros -- fedora and rhel platform_families, nothing else. This is most likely not as useful as the
|
321
|
+
# "fedora_derived?" helper.
|
322
|
+
#
|
323
|
+
# @param [Chef::Node] node the node to check
|
324
|
+
# @since 15.5
|
325
|
+
#
|
326
|
+
# @return [Boolean]
|
327
|
+
#
|
328
|
+
def redhat_based?(node = __getnode)
|
329
|
+
%w{rhel fedora}.include?(node["platform_family"])
|
330
|
+
end
|
331
|
+
|
332
|
+
# All of the Solaris-lineage.
|
333
|
+
#
|
334
|
+
# @param [Chef::Node] node the node to check
|
335
|
+
# @since 15.5
|
336
|
+
#
|
337
|
+
# @return [Boolean]
|
338
|
+
#
|
339
|
+
def solaris_based?(node = __getnode)
|
340
|
+
%w{solaris2 smartos omnios openindiana}.include?(node["platform"])
|
341
|
+
end
|
342
|
+
|
343
|
+
# All of the BSD-lineage.
|
344
|
+
#
|
345
|
+
# Note that macOS is not included since macOS deviates so significantly from BSD that including it would not be useful.
|
346
|
+
#
|
347
|
+
# @param [Chef::Node] node the node to check
|
348
|
+
# @since 15.5
|
349
|
+
#
|
350
|
+
# @return [Boolean]
|
351
|
+
#
|
352
|
+
def bsd_based?(node = __getnode)
|
353
|
+
# we could use os, platform_family or platform here equally
|
354
|
+
%w{netbsd freebsd openbsd dragonflybsd}.include?(node["platform"])
|
355
|
+
end
|
356
|
+
|
357
|
+
extend self
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|