chef 18.9.4 → 18.11.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +16 -12
- data/README.md +0 -1
- data/Rakefile +21 -5
- data/chef-universal-mingw-ucrt.gemspec +4 -2
- data/chef.gemspec +17 -14
- data/lib/chef/application/apply.rb +1 -1
- data/lib/chef/application/base.rb +4 -4
- data/lib/chef/application/exit_code.rb +1 -1
- data/lib/chef/chef_fs/command_line.rb +4 -4
- data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +2 -3
- data/lib/chef/client.rb +2 -3
- data/lib/chef/compliance/fetcher/chef_server.rb +1 -1
- data/lib/chef/compliance/reporter/cli.rb +2 -2
- data/lib/chef/compliance/runner.rb +19 -1
- data/lib/chef/dsl/chef_vault.rb +1 -1
- data/lib/chef/dsl/rest_resource.rb +223 -16
- data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -5
- data/lib/chef/environment.rb +1 -1
- data/lib/chef/exceptions.rb +1 -1
- data/lib/chef/file_cache.rb +1 -5
- data/lib/chef/formatters/error_description.rb +8 -1
- data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +1 -1
- data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
- data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
- data/lib/chef/group.rb +1 -1
- data/lib/chef/handler/slow_report.rb +1 -1
- data/lib/chef/http/authenticator.rb +25 -12
- data/lib/chef/mixin/api_version_request_handling.rb +1 -1
- data/lib/chef/mixin/powershell_type_coercions.rb +2 -2
- data/lib/chef/mixin/securable.rb +2 -2
- data/lib/chef/mixin/template.rb +25 -3
- data/lib/chef/mixin/versioned_api.rb +1 -1
- data/lib/chef/monkey_patches/net-http.rb +8 -8
- data/lib/chef/monkey_patches/reline-windows.rb +116 -0
- data/lib/chef/property.rb +1 -1
- data/lib/chef/provider/cron.rb +1 -1
- data/lib/chef/provider/directory.rb +11 -0
- data/lib/chef/provider/dsc_resource.rb +2 -2
- data/lib/chef/provider/file/content.rb +3 -2
- data/lib/chef/provider/file.rb +1 -1
- data/lib/chef/provider/git.rb +1 -1
- data/lib/chef/provider/ifconfig/debian.rb +1 -1
- data/lib/chef/provider/ifconfig/redhat.rb +1 -1
- data/lib/chef/provider/mount/linux.rb +1 -1
- data/lib/chef/provider/mount/windows.rb +4 -4
- data/lib/chef/provider/package/chocolatey.rb +78 -19
- data/lib/chef/provider/package/dnf/dnf_helper.py +355 -65
- data/lib/chef/provider/package/dnf/python_helper.rb +7 -4
- data/lib/chef/provider/package/dnf.rb +25 -6
- data/lib/chef/provider/package/homebrew.rb +3 -3
- data/lib/chef/provider/package/rubygems.rb +25 -2
- data/lib/chef/provider/package/snap.rb +1 -1
- data/lib/chef/provider/package/windows/exe.rb +1 -1
- data/lib/chef/provider/package/windows/msi.rb +1 -1
- data/lib/chef/provider/package/yum/rpm_utils.rb +2 -2
- data/lib/chef/provider/package/yum.rb +1 -1
- data/lib/chef/provider/powershell_script.rb +84 -84
- data/lib/chef/provider/service/debian.rb +2 -4
- data/lib/chef/provider/user/dscl.rb +1 -1
- data/lib/chef/provider/user/mac.rb +1 -1
- data/lib/chef/provider/windows_script.rb +1 -1
- data/lib/chef/resource/_rest_resource.rb +9 -7
- data/lib/chef/resource/alternatives.rb +41 -41
- data/lib/chef/resource/apt_package.rb +31 -31
- data/lib/chef/resource/apt_preference.rb +22 -22
- data/lib/chef/resource/apt_repository.rb +2 -2
- data/lib/chef/resource/archive_file.rb +52 -18
- data/lib/chef/resource/bash.rb +129 -129
- data/lib/chef/resource/bff_package.rb +15 -15
- data/lib/chef/resource/breakpoint.rb +44 -44
- data/lib/chef/resource/cab_package.rb +22 -22
- data/lib/chef/resource/chef_client_config.rb +251 -89
- data/lib/chef/resource/chef_client_cron.rb +18 -18
- data/lib/chef/resource/chef_client_launchd.rb +1 -1
- data/lib/chef/resource/chef_client_scheduled_task.rb +31 -31
- data/lib/chef/resource/chef_client_systemd_timer.rb +16 -16
- data/lib/chef/resource/chef_client_trusted_certificate.rb +28 -28
- data/lib/chef/resource/chef_handler.rb +107 -107
- data/lib/chef/resource/chef_vault_secret.rb +1 -1
- data/lib/chef/resource/chocolatey_config.rb +14 -14
- data/lib/chef/resource/chocolatey_feature.rb +1 -1
- data/lib/chef/resource/chocolatey_installer.rb +60 -42
- data/lib/chef/resource/chocolatey_package.rb +1 -1
- data/lib/chef/resource/chocolatey_source.rb +15 -15
- data/lib/chef/resource/cron/_cron_shared.rb +0 -2
- data/lib/chef/resource/cron/cron.rb +70 -70
- data/lib/chef/resource/csh.rb +5 -5
- data/lib/chef/resource/directory.rb +6 -6
- data/lib/chef/resource/dpkg_package.rb +3 -3
- data/lib/chef/resource/group.rb +28 -28
- data/lib/chef/resource/habitat/habitat_package.rb +80 -80
- data/lib/chef/resource/habitat/habitat_sup.rb +93 -95
- data/lib/chef/resource/habitat/habitat_sup_systemd.rb +10 -10
- data/lib/chef/resource/habitat/habitat_sup_windows.rb +3 -3
- data/lib/chef/resource/habitat_config.rb +13 -13
- data/lib/chef/resource/habitat_install.rb +17 -17
- data/lib/chef/resource/habitat_service.rb +1 -1
- data/lib/chef/resource/habitat_user_toml.rb +12 -12
- data/lib/chef/resource/helpers/cron_validations.rb +2 -2
- data/lib/chef/resource/homebrew_cask.rb +1 -1
- data/lib/chef/resource/homebrew_package.rb +20 -20
- data/lib/chef/resource/homebrew_tap.rb +1 -1
- data/lib/chef/resource/hostname.rb +2 -2
- data/lib/chef/resource/http_request.rb +2 -2
- data/lib/chef/resource/ifconfig.rb +34 -34
- data/lib/chef/resource/inspec_input.rb +37 -37
- data/lib/chef/resource/inspec_waiver.rb +63 -63
- data/lib/chef/resource/inspec_waiver_file_entry.rb +25 -25
- data/lib/chef/resource/ksh.rb +5 -5
- data/lib/chef/resource/launchd.rb +2 -2
- data/lib/chef/resource/link.rb +8 -8
- data/lib/chef/resource/locale.rb +6 -6
- data/lib/chef/resource/log.rb +4 -4
- data/lib/chef/resource/mdadm.rb +36 -36
- data/lib/chef/resource/mount.rb +3 -3
- data/lib/chef/resource/msu_package.rb +1 -1
- data/lib/chef/resource/ohai.rb +32 -32
- data/lib/chef/resource/ohai_hint.rb +24 -24
- data/lib/chef/resource/openssl_ec_private_key.rb +2 -2
- data/lib/chef/resource/openssl_ec_public_key.rb +2 -2
- data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
- data/lib/chef/resource/openssl_rsa_public_key.rb +2 -2
- data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
- data/lib/chef/resource/openssl_x509_crl.rb +15 -15
- data/lib/chef/resource/openssl_x509_request.rb +2 -2
- data/lib/chef/resource/osx_profile.rb +54 -54
- data/lib/chef/resource/package.rb +6 -6
- data/lib/chef/resource/perl.rb +5 -5
- data/lib/chef/resource/plist.rb +4 -4
- data/lib/chef/resource/powershell_package_source.rb +12 -12
- data/lib/chef/resource/python.rb +4 -4
- data/lib/chef/resource/reboot.rb +5 -5
- data/lib/chef/resource/registry_key.rb +81 -81
- data/lib/chef/resource/remote_file.rb +72 -72
- data/lib/chef/resource/resource_notification.rb +4 -4
- data/lib/chef/resource/rhsm_errata_level.rb +1 -1
- data/lib/chef/resource/rhsm_register.rb +2 -2
- data/lib/chef/resource/scm/git.rb +79 -79
- data/lib/chef/resource/scm/subversion.rb +9 -9
- data/lib/chef/resource/script.rb +3 -3
- data/lib/chef/resource/selinux_boolean.rb +12 -12
- data/lib/chef/resource/selinux_fcontext.rb +21 -21
- data/lib/chef/resource/selinux_install.rb +18 -18
- data/lib/chef/resource/selinux_login.rb +11 -11
- data/lib/chef/resource/selinux_module.rb +16 -16
- data/lib/chef/resource/selinux_permissive.rb +9 -9
- data/lib/chef/resource/selinux_port.rb +16 -16
- data/lib/chef/resource/selinux_state.rb +28 -28
- data/lib/chef/resource/selinux_user.rb +14 -14
- data/lib/chef/resource/service.rb +5 -5
- data/lib/chef/resource/snap_package.rb +16 -16
- data/lib/chef/resource/ssh_known_hosts_entry.rb +10 -10
- data/lib/chef/resource/sudo.rb +68 -68
- data/lib/chef/resource/swap_file.rb +12 -12
- data/lib/chef/resource/sysctl.rb +42 -42
- data/lib/chef/resource/systemd_unit.rb +38 -38
- data/lib/chef/resource/timezone.rb +16 -16
- data/lib/chef/resource/user/mac_user.rb +3 -3
- data/lib/chef/resource/user.rb +6 -6
- data/lib/chef/resource/user_ulimit.rb +22 -22
- data/lib/chef/resource/windows_ad_join.rb +25 -25
- data/lib/chef/resource/windows_audit_policy.rb +34 -34
- data/lib/chef/resource/windows_auto_run.rb +8 -8
- data/lib/chef/resource/windows_certificate.rb +20 -20
- data/lib/chef/resource/windows_defender.rb +22 -22
- data/lib/chef/resource/windows_defender_exclusion.rb +17 -17
- data/lib/chef/resource/windows_env.rb +6 -6
- data/lib/chef/resource/windows_feature.rb +42 -42
- data/lib/chef/resource/windows_feature_dism.rb +8 -8
- data/lib/chef/resource/windows_feature_powershell.rb +20 -20
- data/lib/chef/resource/windows_firewall_profile.rb +28 -28
- data/lib/chef/resource/windows_firewall_rule.rb +47 -47
- data/lib/chef/resource/windows_font.rb +7 -7
- data/lib/chef/resource/windows_package.rb +59 -59
- data/lib/chef/resource/windows_pagefile.rb +29 -29
- data/lib/chef/resource/windows_path.rb +12 -12
- data/lib/chef/resource/windows_printer.rb +28 -28
- data/lib/chef/resource/windows_printer_port.rb +21 -21
- data/lib/chef/resource/windows_security_policy.rb +23 -23
- data/lib/chef/resource/windows_service.rb +108 -108
- data/lib/chef/resource/windows_share.rb +19 -19
- data/lib/chef/resource/windows_shortcut.rb +7 -7
- data/lib/chef/resource/windows_task.rb +105 -105
- data/lib/chef/resource/windows_uac.rb +14 -14
- data/lib/chef/resource/windows_update_settings.rb +27 -27
- data/lib/chef/resource/windows_user_privilege.rb +59 -59
- data/lib/chef/resource/windows_workgroup.rb +12 -12
- data/lib/chef/resource/yum_package.rb +1 -1
- data/lib/chef/resource/yum_repository.rb +36 -36
- data/lib/chef/resource.rb +1 -1
- data/lib/chef/resource_collection/resource_set.rb +2 -3
- data/lib/chef/resource_inspector.rb +1 -2
- data/lib/chef/run_context.rb +2 -2
- data/lib/chef/runner.rb +1 -1
- data/lib/chef/secret_fetcher/akeyless_vault.rb +0 -1
- data/lib/chef/secret_fetcher/hashi_vault.rb +0 -1
- data/lib/chef/shell/ext.rb +20 -20
- data/lib/chef/shell/shell_session.rb +1 -1
- data/lib/chef/shell.rb +7 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/version_constraint.rb +1 -1
- data/lib/chef/win32/file/version_info.rb +1 -1
- metadata +63 -38
|
@@ -172,9 +172,16 @@ class Chef
|
|
|
172
172
|
|
|
173
173
|
if new_resource.owner || new_resource.group
|
|
174
174
|
converge_by("set owner of files extracted in #{new_resource.destination} to #{new_resource.owner}:#{new_resource.group}") do
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
175
|
+
dest_realpath = ::File.expand_path(new_resource.destination)
|
|
176
|
+
Archive::Reader.open_filename(new_resource.path, nil, strip_components: new_resource.strip_components) do |archive|
|
|
177
|
+
archive.each_entry do |e|
|
|
178
|
+
# Validate path is within destination before chown-ing.
|
|
179
|
+
# Use expand_path for security check, original string for the chown call.
|
|
180
|
+
chown_path_expanded = ::File.expand_path("#{new_resource.destination}/#{e.pathname}")
|
|
181
|
+
next unless chown_path_expanded.start_with?(dest_realpath + ::File::SEPARATOR) || chown_path_expanded == dest_realpath
|
|
182
|
+
|
|
183
|
+
FileUtils.chown(new_resource.owner, new_resource.group, "#{new_resource.destination}/#{e.pathname}")
|
|
184
|
+
end
|
|
178
185
|
end
|
|
179
186
|
end
|
|
180
187
|
end
|
|
@@ -211,16 +218,23 @@ class Chef
|
|
|
211
218
|
# @return [Boolean]
|
|
212
219
|
def archive_differs_from_disk?(src, dest)
|
|
213
220
|
modified = false
|
|
214
|
-
|
|
221
|
+
dest_realpath = ::File.expand_path(dest)
|
|
215
222
|
Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}")
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components) do |archive|
|
|
224
|
+
archive.each_entry do |e|
|
|
225
|
+
pathname = ::File.expand_path(e.pathname, dest_realpath)
|
|
226
|
+
# Skip archive entries that resolve outside the destination directory.
|
|
227
|
+
# A traversal entry (e.g. "../escaped") must not influence the mtime
|
|
228
|
+
# comparison and must never trigger extraction.
|
|
229
|
+
next unless pathname.start_with?(dest_realpath + ::File::SEPARATOR) || pathname == dest_realpath
|
|
230
|
+
|
|
231
|
+
if ::File.exist?(pathname)
|
|
232
|
+
Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
|
|
233
|
+
modified = true unless ::File.mtime(pathname) == e.mtime
|
|
234
|
+
else
|
|
235
|
+
Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
|
|
236
|
+
modified = true
|
|
237
|
+
end
|
|
224
238
|
end
|
|
225
239
|
end
|
|
226
240
|
modified
|
|
@@ -235,15 +249,35 @@ class Chef
|
|
|
235
249
|
# @return [void]
|
|
236
250
|
def extract(src, dest, options = [])
|
|
237
251
|
converge_by("extract #{src} to #{dest}") do
|
|
238
|
-
|
|
252
|
+
user_flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|).to_i
|
|
253
|
+
# Always apply libarchive security flags to prevent path traversal.
|
|
254
|
+
# These are not user-overridable hence directly added here
|
|
255
|
+
# instead of options array. NODOTDOT blocks "../" sequences,
|
|
256
|
+
# NOABSOLUTEPATHS blocks absolute-path entries, SECURE_SYMLINKS prevents
|
|
257
|
+
# symlink attacks. Combined with the check below in archive.each_entry
|
|
258
|
+
# they safeguard against Zip Slip / CWE-22 attacks.
|
|
259
|
+
security_flags = Archive::EXTRACT_SECURE_NODOTDOT |
|
|
260
|
+
Archive::EXTRACT_SECURE_NOABSOLUTEPATHS |
|
|
261
|
+
Archive::EXTRACT_SECURE_SYMLINKS
|
|
262
|
+
all_flags = user_flags | security_flags
|
|
263
|
+
dest_realpath = ::File.expand_path(dest)
|
|
239
264
|
|
|
240
265
|
Dir.chdir(dest) do
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
266
|
+
Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components) do |archive|
|
|
267
|
+
archive.each_entry do |e|
|
|
268
|
+
# reject any entry whose resolved path
|
|
269
|
+
# falls outside the destination directory before calling into libarchive.
|
|
270
|
+
entry_realpath = ::File.expand_path(e.pathname, dest_realpath)
|
|
271
|
+
unless entry_realpath.start_with?(dest_realpath + ::File::SEPARATOR) || entry_realpath == dest_realpath
|
|
272
|
+
raise Chef::Exceptions::ValidationFailed,
|
|
273
|
+
"Refusing to extract archive entry #{e.pathname.inspect}: resolved path " \
|
|
274
|
+
"#{entry_realpath.inspect} is outside destination #{dest_realpath.inspect}. " \
|
|
275
|
+
"This archive may contain a path traversal attack."
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
archive.extract(e, all_flags)
|
|
279
|
+
end
|
|
245
280
|
end
|
|
246
|
-
archive.close
|
|
247
281
|
end
|
|
248
282
|
end
|
|
249
283
|
end
|
data/lib/chef/resource/bash.rb
CHANGED
|
@@ -26,135 +26,135 @@ class Chef
|
|
|
26
26
|
|
|
27
27
|
description "Use the **bash** resource to execute scripts using the Bash interpreter. This resource may also use any of the actions and properties that are available to the **execute** resource. Commands that are executed with this resource are (by their nature) not idempotent, as they are typically unique to the environment in which they are run. Use `not_if` and `only_if` to guard this resource for idempotence."
|
|
28
28
|
examples <<~'DOC'
|
|
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
|
-
|
|
29
|
+
**Compile an application**
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
bash 'install_something' do
|
|
33
|
+
user 'root'
|
|
34
|
+
cwd '/tmp'
|
|
35
|
+
code <<-EOH
|
|
36
|
+
wget http://www.example.com/tarball.tar.gz
|
|
37
|
+
tar -zxf tarball.tar.gz
|
|
38
|
+
cd tarball
|
|
39
|
+
./configure
|
|
40
|
+
make
|
|
41
|
+
make install
|
|
42
|
+
EOH
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Using escape characters in a string of code**
|
|
47
|
+
|
|
48
|
+
In the following example, the `find` command uses an escape character (`\`). Use a second escape character (`\\`) to preserve the escape character in the code string:
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
bash 'delete some archives ' do
|
|
52
|
+
code <<-EOH
|
|
53
|
+
find ./ -name "*.tar.Z" -mtime +180 -exec rm -f {} \\;
|
|
54
|
+
EOH
|
|
55
|
+
ignore_failure true
|
|
56
|
+
end
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Install a file from a remote location**
|
|
60
|
+
|
|
61
|
+
The following is an example of how to install the foo123 module for Nginx. This module adds shell-style functionality to an Nginx configuration file and does the following:
|
|
62
|
+
|
|
63
|
+
- Declares three variables
|
|
64
|
+
- Gets the Nginx file from a remote location
|
|
65
|
+
- Installs the file using Bash to the path specified by the `src_filepath` variable
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
src_filename = "foo123-nginx-module-v#{node['nginx']['foo123']['version']}.tar.gz"
|
|
69
|
+
src_filepath = "#{Chef::Config['file_cache_path']}/#{src_filename}"
|
|
70
|
+
extract_path = "#{Chef::Config['file_cache_path']}/nginx_foo123_module/#{node['nginx']['foo123']['checksum']}"
|
|
71
|
+
|
|
72
|
+
remote_file 'src_filepath' do
|
|
73
|
+
source node['nginx']['foo123']['url']
|
|
74
|
+
checksum node['nginx']['foo123']['checksum']
|
|
75
|
+
owner 'root'
|
|
76
|
+
group 'root'
|
|
77
|
+
mode '0755'
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
bash 'extract_module' do
|
|
81
|
+
cwd ::File.dirname(src_filepath)
|
|
82
|
+
code <<-EOH
|
|
83
|
+
mkdir -p #{extract_path}
|
|
84
|
+
tar xzf #{src_filename} -C #{extract_path}
|
|
85
|
+
mv #{extract_path}/*/* #{extract_path}/
|
|
86
|
+
EOH
|
|
87
|
+
not_if { ::File.exist?(extract_path) }
|
|
88
|
+
end
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Install an application from git**
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
git "#{Chef::Config[:file_cache_path]}/ruby-build" do
|
|
95
|
+
repository 'git://github.com/rbenv/ruby-build.git'
|
|
96
|
+
revision 'master'
|
|
97
|
+
action :sync
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
bash 'install_ruby_build' do
|
|
101
|
+
cwd "#{Chef::Config[:file_cache_path]}/ruby-build"
|
|
102
|
+
user 'rbenv'
|
|
103
|
+
group 'rbenv'
|
|
104
|
+
code <<-EOH
|
|
105
|
+
./install.sh
|
|
106
|
+
EOH
|
|
107
|
+
environment 'PREFIX' => '/usr/local'
|
|
108
|
+
end
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
**Using Attributes in Bash Code**
|
|
112
|
+
|
|
113
|
+
The following recipe shows how an attributes file can be used to store certain settings. An attributes file is located in the `attributes/`` directory in the same cookbook as the recipe which calls the attributes file. In this example, the attributes file specifies certain settings for Python that are then used across all nodes against which this recipe will run.
|
|
114
|
+
|
|
115
|
+
Python packages have versions, installation directories, URLs, and checksum files. An attributes file that exists to support this type of recipe would include settings like the following:
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
default['python']['version'] = '2.7.1'
|
|
119
|
+
|
|
120
|
+
if python['install_method'] == 'package'
|
|
121
|
+
default['python']['prefix_dir'] = '/usr'
|
|
122
|
+
else
|
|
123
|
+
default['python']['prefix_dir'] = '/usr/local'
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
default['python']['url'] = 'http://www.python.org/ftp/python'
|
|
127
|
+
default['python']['checksum'] = '80e387...85fd61'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
and then the methods in the recipe may refer to these values. A recipe that is used to install Python will need to do the following:
|
|
131
|
+
|
|
132
|
+
- Identify each package to be installed (implied in this example, not shown)
|
|
133
|
+
- Define variables for the package `version` and the `install_path`
|
|
134
|
+
- Get the package from a remote location, but only if the package does not already exist on the target system
|
|
135
|
+
- Use the **bash** resource to install the package on the node, but only when the package is not already installed
|
|
136
|
+
|
|
137
|
+
```ruby
|
|
138
|
+
version = node['python']['version']
|
|
139
|
+
install_path = "#{node['python']['prefix_dir']}/lib/python#{version.split(/(^\d+\.\d+)/)[1]}"
|
|
140
|
+
|
|
141
|
+
remote_file "#{Chef::Config[:file_cache_path]}/Python-#{version}.tar.bz2" do
|
|
142
|
+
source "#{node['python']['url']}/#{version}/Python-#{version}.tar.bz2"
|
|
143
|
+
checksum node['python']['checksum']
|
|
144
|
+
mode '0755'
|
|
145
|
+
not_if { ::File.exist?(install_path) }
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
bash 'build-and-install-python' do
|
|
149
|
+
cwd Chef::Config[:file_cache_path]
|
|
150
|
+
code <<-EOF
|
|
151
|
+
tar -jxvf Python-#{version}.tar.bz2
|
|
152
|
+
(cd Python-#{version} && ./configure #{configure_options})
|
|
153
|
+
(cd Python-#{version} && make && make install)
|
|
154
|
+
EOF
|
|
155
|
+
not_if { ::File.exist?(install_path) }
|
|
156
|
+
end
|
|
157
|
+
```
|
|
158
158
|
DOC
|
|
159
159
|
|
|
160
160
|
def initialize(name, run_context = nil)
|
|
@@ -28,25 +28,25 @@ class Chef
|
|
|
28
28
|
description "Use the **bff_package** resource to manage packages for the AIX platform using the installp utility. When a package is installed from a local file, it must be added to the node using the **remote_file** or **cookbook_file** resources."
|
|
29
29
|
introduced "12.0"
|
|
30
30
|
examples <<~DOC
|
|
31
|
-
|
|
31
|
+
The **bff_package** resource is the default package provider on the AIX platform. The base **package** resource may be used, and then when the platform is AIX, #{ChefUtils::Dist::Infra::PRODUCT} will identify the correct package provider. The following examples show how to install part of the IBM XL C/C++ compiler.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
**Installing using the base package resource**
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
```ruby
|
|
36
|
+
package 'xlccmp.13.1.0' do
|
|
37
|
+
source '/var/tmp/IBM_XL_C_13.1.0/usr/sys/inst.images/xlccmp.13.1.0'
|
|
38
|
+
action :install
|
|
39
|
+
end
|
|
40
|
+
```
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
**Installing using the bff_package resource**
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
```ruby
|
|
45
|
+
bff_package 'xlccmp.13.1.0' do
|
|
46
|
+
source '/var/tmp/IBM_XL_C_13.1.0/usr/sys/inst.images/xlccmp.13.1.0'
|
|
47
|
+
action :install
|
|
48
|
+
end
|
|
49
|
+
```
|
|
50
50
|
DOC
|
|
51
51
|
|
|
52
52
|
property :package_name, String,
|
|
@@ -28,61 +28,61 @@ class Chef
|
|
|
28
28
|
description "Use the **breakpoint** resource to add breakpoints to recipes. Run the #{ChefUtils::Dist::Infra::SHELL} in #{ChefUtils::Dist::Infra::PRODUCT} mode, and then use those breakpoints to debug recipes. Breakpoints are ignored by the #{ChefUtils::Dist::Infra::CLIENT} during an actual #{ChefUtils::Dist::Infra::CLIENT} run. That said, breakpoints are typically used to debug recipes only when running them in a non-production environment, after which they are removed from those recipes before the parent cookbook is uploaded to the Chef server."
|
|
29
29
|
introduced "12.0"
|
|
30
30
|
examples <<~DOC
|
|
31
|
-
|
|
31
|
+
**A recipe without a breakpoint**
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
```ruby
|
|
34
|
+
yum_key node['yum']['elrepo']['key'] do
|
|
35
|
+
url node['yum']['elrepo']['key_url']
|
|
36
|
+
action :add
|
|
37
|
+
end
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
yum_repository 'elrepo' do
|
|
40
|
+
description 'ELRepo.org Community Enterprise Linux Extras Repository'
|
|
41
|
+
key node['yum']['elrepo']['key']
|
|
42
|
+
mirrorlist node['yum']['elrepo']['url']
|
|
43
|
+
includepkgs node['yum']['elrepo']['includepkgs']
|
|
44
|
+
exclude node['yum']['elrepo']['exclude']
|
|
45
|
+
action :create
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
**The same recipe with breakpoints**
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
In the following example, the name of each breakpoint is an arbitrary string.
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
```ruby
|
|
54
|
+
breakpoint "before yum_key node['yum']['repo_name']['key']" do
|
|
55
|
+
action :break
|
|
56
|
+
end
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
yum_key node['yum']['repo_name']['key'] do
|
|
59
|
+
url node['yum']['repo_name']['key_url']
|
|
60
|
+
action :add
|
|
61
|
+
end
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
breakpoint "after yum_key node['yum']['repo_name']['key']" do
|
|
64
|
+
action :break
|
|
65
|
+
end
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
breakpoint "before yum_repository 'repo_name'" do
|
|
68
|
+
action :break
|
|
69
|
+
end
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
yum_repository 'repo_name' do
|
|
72
|
+
description 'description'
|
|
73
|
+
key node['yum']['repo_name']['key']
|
|
74
|
+
mirrorlist node['yum']['repo_name']['url']
|
|
75
|
+
includepkgs node['yum']['repo_name']['includepkgs']
|
|
76
|
+
exclude node['yum']['repo_name']['exclude']
|
|
77
|
+
action :create
|
|
78
|
+
end
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
breakpoint "after yum_repository 'repo_name'" do
|
|
81
|
+
action :break
|
|
82
|
+
end
|
|
83
|
+
```
|
|
84
84
|
|
|
85
|
-
|
|
85
|
+
In the previous examples, the names are used to indicate if the breakpoint is before or after a resource and also to specify which resource it is before or after.
|
|
86
86
|
DOC
|
|
87
87
|
|
|
88
88
|
default_action :break
|
|
@@ -29,33 +29,33 @@ class Chef
|
|
|
29
29
|
description "Use the **cab_package** resource to install or remove Microsoft Windows cabinet (.cab) packages."
|
|
30
30
|
introduced "12.15"
|
|
31
31
|
examples <<~'DOC'
|
|
32
|
-
|
|
32
|
+
**Using local path in source**
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
```ruby
|
|
35
|
+
cab_package 'Install .NET 3.5 sp1 via KB958488' do
|
|
36
|
+
source 'C:\Users\xyz\AppData\Local\Temp\Windows6.1-KB958488-x64.cab'
|
|
37
|
+
action :install
|
|
38
|
+
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
cab_package 'Remove .NET 3.5 sp1 via KB958488' do
|
|
41
|
+
source 'C:\Users\xyz\AppData\Local\Temp\Windows6.1-KB958488-x64.cab'
|
|
42
|
+
action :remove
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
**Using URL in source**
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
```ruby
|
|
49
|
+
cab_package 'Install .NET 3.5 sp1 via KB958488' do
|
|
50
|
+
source 'https://s3.amazonaws.com/my_bucket/Windows6.1-KB958488-x64.cab'
|
|
51
|
+
action :install
|
|
52
|
+
end
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
cab_package 'Remove .NET 3.5 sp1 via KB958488' do
|
|
55
|
+
source 'https://s3.amazonaws.com/my_bucket/Temp\Windows6.1-KB958488-x64.cab'
|
|
56
|
+
action :remove
|
|
57
|
+
end
|
|
58
|
+
```
|
|
59
59
|
DOC
|
|
60
60
|
|
|
61
61
|
allowed_actions :install, :remove
|