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.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +16 -12
  3. data/README.md +0 -1
  4. data/Rakefile +21 -5
  5. data/chef-universal-mingw-ucrt.gemspec +4 -2
  6. data/chef.gemspec +17 -14
  7. data/lib/chef/application/apply.rb +1 -1
  8. data/lib/chef/application/base.rb +4 -4
  9. data/lib/chef/application/exit_code.rb +1 -1
  10. data/lib/chef/chef_fs/command_line.rb +4 -4
  11. data/lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb +1 -1
  12. data/lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb +2 -3
  13. data/lib/chef/client.rb +2 -3
  14. data/lib/chef/compliance/fetcher/chef_server.rb +1 -1
  15. data/lib/chef/compliance/reporter/cli.rb +2 -2
  16. data/lib/chef/compliance/runner.rb +19 -1
  17. data/lib/chef/dsl/chef_vault.rb +1 -1
  18. data/lib/chef/dsl/rest_resource.rb +223 -16
  19. data/lib/chef/encrypted_data_bag_item/decryptor.rb +1 -5
  20. data/lib/chef/environment.rb +1 -1
  21. data/lib/chef/exceptions.rb +1 -1
  22. data/lib/chef/file_cache.rb +1 -5
  23. data/lib/chef/formatters/error_description.rb +8 -1
  24. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +1 -1
  25. data/lib/chef/formatters/error_inspectors/cookbook_resolve_error_inspector.rb +1 -1
  26. data/lib/chef/formatters/error_inspectors/cookbook_sync_error_inspector.rb +1 -1
  27. data/lib/chef/group.rb +1 -1
  28. data/lib/chef/handler/slow_report.rb +1 -1
  29. data/lib/chef/http/authenticator.rb +25 -12
  30. data/lib/chef/mixin/api_version_request_handling.rb +1 -1
  31. data/lib/chef/mixin/powershell_type_coercions.rb +2 -2
  32. data/lib/chef/mixin/securable.rb +2 -2
  33. data/lib/chef/mixin/template.rb +25 -3
  34. data/lib/chef/mixin/versioned_api.rb +1 -1
  35. data/lib/chef/monkey_patches/net-http.rb +8 -8
  36. data/lib/chef/monkey_patches/reline-windows.rb +116 -0
  37. data/lib/chef/property.rb +1 -1
  38. data/lib/chef/provider/cron.rb +1 -1
  39. data/lib/chef/provider/directory.rb +11 -0
  40. data/lib/chef/provider/dsc_resource.rb +2 -2
  41. data/lib/chef/provider/file/content.rb +3 -2
  42. data/lib/chef/provider/file.rb +1 -1
  43. data/lib/chef/provider/git.rb +1 -1
  44. data/lib/chef/provider/ifconfig/debian.rb +1 -1
  45. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  46. data/lib/chef/provider/mount/linux.rb +1 -1
  47. data/lib/chef/provider/mount/windows.rb +4 -4
  48. data/lib/chef/provider/package/chocolatey.rb +78 -19
  49. data/lib/chef/provider/package/dnf/dnf_helper.py +355 -65
  50. data/lib/chef/provider/package/dnf/python_helper.rb +7 -4
  51. data/lib/chef/provider/package/dnf.rb +25 -6
  52. data/lib/chef/provider/package/homebrew.rb +3 -3
  53. data/lib/chef/provider/package/rubygems.rb +25 -2
  54. data/lib/chef/provider/package/snap.rb +1 -1
  55. data/lib/chef/provider/package/windows/exe.rb +1 -1
  56. data/lib/chef/provider/package/windows/msi.rb +1 -1
  57. data/lib/chef/provider/package/yum/rpm_utils.rb +2 -2
  58. data/lib/chef/provider/package/yum.rb +1 -1
  59. data/lib/chef/provider/powershell_script.rb +84 -84
  60. data/lib/chef/provider/service/debian.rb +2 -4
  61. data/lib/chef/provider/user/dscl.rb +1 -1
  62. data/lib/chef/provider/user/mac.rb +1 -1
  63. data/lib/chef/provider/windows_script.rb +1 -1
  64. data/lib/chef/resource/_rest_resource.rb +9 -7
  65. data/lib/chef/resource/alternatives.rb +41 -41
  66. data/lib/chef/resource/apt_package.rb +31 -31
  67. data/lib/chef/resource/apt_preference.rb +22 -22
  68. data/lib/chef/resource/apt_repository.rb +2 -2
  69. data/lib/chef/resource/archive_file.rb +52 -18
  70. data/lib/chef/resource/bash.rb +129 -129
  71. data/lib/chef/resource/bff_package.rb +15 -15
  72. data/lib/chef/resource/breakpoint.rb +44 -44
  73. data/lib/chef/resource/cab_package.rb +22 -22
  74. data/lib/chef/resource/chef_client_config.rb +251 -89
  75. data/lib/chef/resource/chef_client_cron.rb +18 -18
  76. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  77. data/lib/chef/resource/chef_client_scheduled_task.rb +31 -31
  78. data/lib/chef/resource/chef_client_systemd_timer.rb +16 -16
  79. data/lib/chef/resource/chef_client_trusted_certificate.rb +28 -28
  80. data/lib/chef/resource/chef_handler.rb +107 -107
  81. data/lib/chef/resource/chef_vault_secret.rb +1 -1
  82. data/lib/chef/resource/chocolatey_config.rb +14 -14
  83. data/lib/chef/resource/chocolatey_feature.rb +1 -1
  84. data/lib/chef/resource/chocolatey_installer.rb +60 -42
  85. data/lib/chef/resource/chocolatey_package.rb +1 -1
  86. data/lib/chef/resource/chocolatey_source.rb +15 -15
  87. data/lib/chef/resource/cron/_cron_shared.rb +0 -2
  88. data/lib/chef/resource/cron/cron.rb +70 -70
  89. data/lib/chef/resource/csh.rb +5 -5
  90. data/lib/chef/resource/directory.rb +6 -6
  91. data/lib/chef/resource/dpkg_package.rb +3 -3
  92. data/lib/chef/resource/group.rb +28 -28
  93. data/lib/chef/resource/habitat/habitat_package.rb +80 -80
  94. data/lib/chef/resource/habitat/habitat_sup.rb +93 -95
  95. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +10 -10
  96. data/lib/chef/resource/habitat/habitat_sup_windows.rb +3 -3
  97. data/lib/chef/resource/habitat_config.rb +13 -13
  98. data/lib/chef/resource/habitat_install.rb +17 -17
  99. data/lib/chef/resource/habitat_service.rb +1 -1
  100. data/lib/chef/resource/habitat_user_toml.rb +12 -12
  101. data/lib/chef/resource/helpers/cron_validations.rb +2 -2
  102. data/lib/chef/resource/homebrew_cask.rb +1 -1
  103. data/lib/chef/resource/homebrew_package.rb +20 -20
  104. data/lib/chef/resource/homebrew_tap.rb +1 -1
  105. data/lib/chef/resource/hostname.rb +2 -2
  106. data/lib/chef/resource/http_request.rb +2 -2
  107. data/lib/chef/resource/ifconfig.rb +34 -34
  108. data/lib/chef/resource/inspec_input.rb +37 -37
  109. data/lib/chef/resource/inspec_waiver.rb +63 -63
  110. data/lib/chef/resource/inspec_waiver_file_entry.rb +25 -25
  111. data/lib/chef/resource/ksh.rb +5 -5
  112. data/lib/chef/resource/launchd.rb +2 -2
  113. data/lib/chef/resource/link.rb +8 -8
  114. data/lib/chef/resource/locale.rb +6 -6
  115. data/lib/chef/resource/log.rb +4 -4
  116. data/lib/chef/resource/mdadm.rb +36 -36
  117. data/lib/chef/resource/mount.rb +3 -3
  118. data/lib/chef/resource/msu_package.rb +1 -1
  119. data/lib/chef/resource/ohai.rb +32 -32
  120. data/lib/chef/resource/ohai_hint.rb +24 -24
  121. data/lib/chef/resource/openssl_ec_private_key.rb +2 -2
  122. data/lib/chef/resource/openssl_ec_public_key.rb +2 -2
  123. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
  124. data/lib/chef/resource/openssl_rsa_public_key.rb +2 -2
  125. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  126. data/lib/chef/resource/openssl_x509_crl.rb +15 -15
  127. data/lib/chef/resource/openssl_x509_request.rb +2 -2
  128. data/lib/chef/resource/osx_profile.rb +54 -54
  129. data/lib/chef/resource/package.rb +6 -6
  130. data/lib/chef/resource/perl.rb +5 -5
  131. data/lib/chef/resource/plist.rb +4 -4
  132. data/lib/chef/resource/powershell_package_source.rb +12 -12
  133. data/lib/chef/resource/python.rb +4 -4
  134. data/lib/chef/resource/reboot.rb +5 -5
  135. data/lib/chef/resource/registry_key.rb +81 -81
  136. data/lib/chef/resource/remote_file.rb +72 -72
  137. data/lib/chef/resource/resource_notification.rb +4 -4
  138. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  139. data/lib/chef/resource/rhsm_register.rb +2 -2
  140. data/lib/chef/resource/scm/git.rb +79 -79
  141. data/lib/chef/resource/scm/subversion.rb +9 -9
  142. data/lib/chef/resource/script.rb +3 -3
  143. data/lib/chef/resource/selinux_boolean.rb +12 -12
  144. data/lib/chef/resource/selinux_fcontext.rb +21 -21
  145. data/lib/chef/resource/selinux_install.rb +18 -18
  146. data/lib/chef/resource/selinux_login.rb +11 -11
  147. data/lib/chef/resource/selinux_module.rb +16 -16
  148. data/lib/chef/resource/selinux_permissive.rb +9 -9
  149. data/lib/chef/resource/selinux_port.rb +16 -16
  150. data/lib/chef/resource/selinux_state.rb +28 -28
  151. data/lib/chef/resource/selinux_user.rb +14 -14
  152. data/lib/chef/resource/service.rb +5 -5
  153. data/lib/chef/resource/snap_package.rb +16 -16
  154. data/lib/chef/resource/ssh_known_hosts_entry.rb +10 -10
  155. data/lib/chef/resource/sudo.rb +68 -68
  156. data/lib/chef/resource/swap_file.rb +12 -12
  157. data/lib/chef/resource/sysctl.rb +42 -42
  158. data/lib/chef/resource/systemd_unit.rb +38 -38
  159. data/lib/chef/resource/timezone.rb +16 -16
  160. data/lib/chef/resource/user/mac_user.rb +3 -3
  161. data/lib/chef/resource/user.rb +6 -6
  162. data/lib/chef/resource/user_ulimit.rb +22 -22
  163. data/lib/chef/resource/windows_ad_join.rb +25 -25
  164. data/lib/chef/resource/windows_audit_policy.rb +34 -34
  165. data/lib/chef/resource/windows_auto_run.rb +8 -8
  166. data/lib/chef/resource/windows_certificate.rb +20 -20
  167. data/lib/chef/resource/windows_defender.rb +22 -22
  168. data/lib/chef/resource/windows_defender_exclusion.rb +17 -17
  169. data/lib/chef/resource/windows_env.rb +6 -6
  170. data/lib/chef/resource/windows_feature.rb +42 -42
  171. data/lib/chef/resource/windows_feature_dism.rb +8 -8
  172. data/lib/chef/resource/windows_feature_powershell.rb +20 -20
  173. data/lib/chef/resource/windows_firewall_profile.rb +28 -28
  174. data/lib/chef/resource/windows_firewall_rule.rb +47 -47
  175. data/lib/chef/resource/windows_font.rb +7 -7
  176. data/lib/chef/resource/windows_package.rb +59 -59
  177. data/lib/chef/resource/windows_pagefile.rb +29 -29
  178. data/lib/chef/resource/windows_path.rb +12 -12
  179. data/lib/chef/resource/windows_printer.rb +28 -28
  180. data/lib/chef/resource/windows_printer_port.rb +21 -21
  181. data/lib/chef/resource/windows_security_policy.rb +23 -23
  182. data/lib/chef/resource/windows_service.rb +108 -108
  183. data/lib/chef/resource/windows_share.rb +19 -19
  184. data/lib/chef/resource/windows_shortcut.rb +7 -7
  185. data/lib/chef/resource/windows_task.rb +105 -105
  186. data/lib/chef/resource/windows_uac.rb +14 -14
  187. data/lib/chef/resource/windows_update_settings.rb +27 -27
  188. data/lib/chef/resource/windows_user_privilege.rb +59 -59
  189. data/lib/chef/resource/windows_workgroup.rb +12 -12
  190. data/lib/chef/resource/yum_package.rb +1 -1
  191. data/lib/chef/resource/yum_repository.rb +36 -36
  192. data/lib/chef/resource.rb +1 -1
  193. data/lib/chef/resource_collection/resource_set.rb +2 -3
  194. data/lib/chef/resource_inspector.rb +1 -2
  195. data/lib/chef/run_context.rb +2 -2
  196. data/lib/chef/runner.rb +1 -1
  197. data/lib/chef/secret_fetcher/akeyless_vault.rb +0 -1
  198. data/lib/chef/secret_fetcher/hashi_vault.rb +0 -1
  199. data/lib/chef/shell/ext.rb +20 -20
  200. data/lib/chef/shell/shell_session.rb +1 -1
  201. data/lib/chef/shell.rb +7 -0
  202. data/lib/chef/version.rb +1 -1
  203. data/lib/chef/version_constraint.rb +1 -1
  204. data/lib/chef/win32/file/version_info.rb +1 -1
  205. 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
- archive = Archive::Reader.open_filename(new_resource.path, nil, strip_components: new_resource.strip_components)
176
- archive.each_entry do |e|
177
- FileUtils.chown(new_resource.owner, new_resource.group, "#{new_resource.destination}/#{e.pathname}")
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
- archive = Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components)
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
- archive.each_entry do |e|
217
- pathname = ::File.expand_path(e.pathname, dest)
218
- if ::File.exist?(pathname)
219
- Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
220
- modified = true unless ::File.mtime(pathname) == e.mtime
221
- else
222
- Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
223
- modified = true
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
- flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|)
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
- archive = Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components)
242
-
243
- archive.each_entry do |e|
244
- archive.extract(e, flags.to_i)
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
@@ -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
- **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
- ```
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
- 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.
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
- **Installing using the base package resource**
33
+ **Installing using the base package resource**
34
34
 
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
- ```
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
- **Installing using the bff_package resource**
42
+ **Installing using the bff_package resource**
43
43
 
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
- ```
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
- **A recipe without a breakpoint**
31
+ **A recipe without a breakpoint**
32
32
 
33
- ```ruby
34
- yum_key node['yum']['elrepo']['key'] do
35
- url node['yum']['elrepo']['key_url']
36
- action :add
37
- end
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
- 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
- ```
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
- **The same recipe with breakpoints**
49
+ **The same recipe with breakpoints**
50
50
 
51
- In the following example, the name of each breakpoint is an arbitrary string.
51
+ In the following example, the name of each breakpoint is an arbitrary string.
52
52
 
53
- ```ruby
54
- breakpoint "before yum_key node['yum']['repo_name']['key']" do
55
- action :break
56
- end
53
+ ```ruby
54
+ breakpoint "before yum_key node['yum']['repo_name']['key']" do
55
+ action :break
56
+ end
57
57
 
58
- yum_key node['yum']['repo_name']['key'] do
59
- url node['yum']['repo_name']['key_url']
60
- action :add
61
- end
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
- breakpoint "after yum_key node['yum']['repo_name']['key']" do
64
- action :break
65
- end
63
+ breakpoint "after yum_key node['yum']['repo_name']['key']" do
64
+ action :break
65
+ end
66
66
 
67
- breakpoint "before yum_repository 'repo_name'" do
68
- action :break
69
- end
67
+ breakpoint "before yum_repository 'repo_name'" do
68
+ action :break
69
+ end
70
70
 
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
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
- breakpoint "after yum_repository 'repo_name'" do
81
- action :break
82
- end
83
- ```
80
+ breakpoint "after yum_repository 'repo_name'" do
81
+ action :break
82
+ end
83
+ ```
84
84
 
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.
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
- **Using local path in source**
32
+ **Using local path in source**
33
33
 
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
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
- 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
- ```
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
- **Using URL in source**
46
+ **Using URL in source**
47
47
 
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
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
- 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
- ```
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