chef 17.1.35-universal-mingw32 → 17.4.38-universal-mingw32

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 (198) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -4
  3. data/chef.gemspec +1 -0
  4. data/lib/chef/action_collection.rb +6 -26
  5. data/lib/chef/application/base.rb +15 -0
  6. data/lib/chef/application.rb +4 -2
  7. data/lib/chef/client.rb +7 -1
  8. data/lib/chef/compliance/default_attributes.rb +5 -3
  9. data/lib/chef/compliance/reporter/automate.rb +1 -1
  10. data/lib/chef/compliance/runner.rb +16 -2
  11. data/lib/chef/cookbook_version.rb +26 -4
  12. data/lib/chef/data_collector/run_end_message.rb +1 -1
  13. data/lib/chef/data_collector.rb +0 -1
  14. data/lib/chef/deprecated.rb +14 -4
  15. data/lib/chef/dsl/render_helpers.rb +44 -0
  16. data/lib/chef/dsl/secret.rb +64 -0
  17. data/lib/chef/dsl/toml.rb +116 -0
  18. data/lib/chef/dsl/universal.rb +5 -0
  19. data/lib/chef/dsl.rb +1 -0
  20. data/lib/chef/event_dispatch/base.rb +2 -1
  21. data/lib/chef/exceptions.rb +23 -0
  22. data/lib/chef/formatters/doc.rb +14 -13
  23. data/lib/chef/formatters/error_mapper.rb +2 -2
  24. data/lib/chef/formatters/minimal.rb +6 -5
  25. data/lib/chef/handler/slow_report.rb +66 -0
  26. data/lib/chef/handler.rb +46 -8
  27. data/lib/chef/http.rb +5 -5
  28. data/lib/chef/json_compat.rb +1 -1
  29. data/lib/chef/node.rb +20 -19
  30. data/lib/chef/policy_builder/policyfile.rb +88 -45
  31. data/lib/chef/provider/execute.rb +1 -1
  32. data/lib/chef/provider/file.rb +2 -2
  33. data/lib/chef/provider/group/dscl.rb +1 -1
  34. data/lib/chef/provider/launchd.rb +6 -6
  35. data/lib/chef/provider/lwrp_base.rb +1 -1
  36. data/lib/chef/provider/package/habitat.rb +168 -0
  37. data/lib/chef/provider/package/powershell.rb +5 -0
  38. data/lib/chef/provider/subversion.rb +4 -4
  39. data/lib/chef/provider/support/yum_repo.erb +1 -1
  40. data/lib/chef/provider/support/zypper_repo.erb +4 -2
  41. data/lib/chef/provider/systemd_unit.rb +17 -16
  42. data/lib/chef/provider/user/mac.rb +3 -3
  43. data/lib/chef/provider/yum_repository.rb +27 -43
  44. data/lib/chef/provider/zypper_repository.rb +30 -34
  45. data/lib/chef/provider.rb +26 -1
  46. data/lib/chef/provider_resolver.rb +8 -2
  47. data/lib/chef/providers.rb +1 -0
  48. data/lib/chef/resource/alternatives.rb +5 -5
  49. data/lib/chef/resource/apt_preference.rb +2 -2
  50. data/lib/chef/resource/apt_repository.rb +2 -2
  51. data/lib/chef/resource/apt_update.rb +4 -4
  52. data/lib/chef/resource/build_essential.rb +1 -1
  53. data/lib/chef/resource/chef_client_config.rb +10 -5
  54. data/lib/chef/resource/chef_client_cron.rb +3 -3
  55. data/lib/chef/resource/chef_client_launchd.rb +3 -3
  56. data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
  57. data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
  58. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  59. data/lib/chef/resource/chef_handler.rb +2 -2
  60. data/lib/chef/resource/chef_sleep.rb +1 -1
  61. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  62. data/lib/chef/resource/chocolatey_feature.rb +2 -2
  63. data/lib/chef/resource/chocolatey_source.rb +1 -1
  64. data/lib/chef/resource/cron/cron_d.rb +4 -6
  65. data/lib/chef/resource/cron_access.rb +1 -1
  66. data/lib/chef/resource/dmg_package.rb +1 -1
  67. data/lib/chef/resource/dsc_resource.rb +1 -1
  68. data/lib/chef/resource/execute.rb +5 -5
  69. data/lib/chef/resource/gem_package.rb +2 -1
  70. data/lib/chef/resource/group.rb +4 -4
  71. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  72. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  73. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  74. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  75. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  76. data/lib/chef/resource/habitat_config.rb +107 -0
  77. data/lib/chef/resource/habitat_install.rb +247 -0
  78. data/lib/chef/resource/habitat_service.rb +451 -0
  79. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  80. data/lib/chef/resource/homebrew_cask.rb +18 -7
  81. data/lib/chef/resource/homebrew_package.rb +1 -1
  82. data/lib/chef/resource/homebrew_tap.rb +4 -3
  83. data/lib/chef/resource/homebrew_update.rb +2 -2
  84. data/lib/chef/resource/hostname.rb +49 -7
  85. data/lib/chef/resource/inspec_waiver_file_entry.rb +8 -7
  86. data/lib/chef/resource/kernel_module.rb +6 -6
  87. data/lib/chef/resource/launchd.rb +3 -3
  88. data/lib/chef/resource/locale.rb +1 -1
  89. data/lib/chef/resource/lwrp_base.rb +1 -1
  90. data/lib/chef/resource/macos_userdefaults.rb +2 -2
  91. data/lib/chef/resource/ohai_hint.rb +2 -6
  92. data/lib/chef/resource/openbsd_package.rb +17 -0
  93. data/lib/chef/resource/openssl_dhparam.rb +1 -2
  94. data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
  95. data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
  96. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
  97. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
  98. data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
  99. data/lib/chef/resource/openssl_x509_crl.rb +1 -3
  100. data/lib/chef/resource/openssl_x509_request.rb +1 -3
  101. data/lib/chef/resource/osx_profile.rb +3 -3
  102. data/lib/chef/resource/plist.rb +1 -1
  103. data/lib/chef/resource/powershell_package_source.rb +2 -4
  104. data/lib/chef/resource/reboot.rb +38 -9
  105. data/lib/chef/resource/remote_directory.rb +2 -2
  106. data/lib/chef/resource/remote_file.rb +1 -1
  107. data/lib/chef/resource/rhsm_errata.rb +0 -2
  108. data/lib/chef/resource/rhsm_errata_level.rb +1 -5
  109. data/lib/chef/resource/rhsm_repo.rb +15 -0
  110. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  111. data/lib/chef/resource/ruby_block.rb +100 -0
  112. data/lib/chef/resource/scm/subversion.rb +1 -1
  113. data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
  114. data/lib/chef/resource/sudo.rb +2 -6
  115. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  116. data/lib/chef/resource/support/client.erb +8 -1
  117. data/lib/chef/resource/support/sup.toml.erb +179 -0
  118. data/lib/chef/resource/swap_file.rb +2 -6
  119. data/lib/chef/resource/sysctl.rb +2 -2
  120. data/lib/chef/resource/systemd_unit.rb +3 -3
  121. data/lib/chef/resource/timezone.rb +1 -1
  122. data/lib/chef/resource/user_ulimit.rb +2 -2
  123. data/lib/chef/resource/windows_ad_join.rb +2 -2
  124. data/lib/chef/resource/windows_audit_policy.rb +2 -2
  125. data/lib/chef/resource/windows_auto_run.rb +2 -2
  126. data/lib/chef/resource/windows_certificate.rb +1 -1
  127. data/lib/chef/resource/windows_defender.rb +163 -0
  128. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  129. data/lib/chef/resource/windows_dfs_folder.rb +2 -2
  130. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  131. data/lib/chef/resource/windows_dns_record.rb +2 -2
  132. data/lib/chef/resource/windows_dns_zone.rb +2 -2
  133. data/lib/chef/resource/windows_feature.rb +3 -3
  134. data/lib/chef/resource/windows_feature_dism.rb +3 -5
  135. data/lib/chef/resource/windows_feature_powershell.rb +3 -3
  136. data/lib/chef/resource/windows_firewall_profile.rb +2 -2
  137. data/lib/chef/resource/windows_firewall_rule.rb +20 -6
  138. data/lib/chef/resource/windows_font.rb +1 -1
  139. data/lib/chef/resource/windows_pagefile.rb +103 -64
  140. data/lib/chef/resource/windows_path.rb +2 -2
  141. data/lib/chef/resource/windows_printer.rb +80 -61
  142. data/lib/chef/resource/windows_printer_port.rb +48 -65
  143. data/lib/chef/resource/windows_security_policy.rb +2 -2
  144. data/lib/chef/resource/windows_share.rb +2 -2
  145. data/lib/chef/resource/windows_shortcut.rb +1 -1
  146. data/lib/chef/resource/windows_task.rb +1 -1
  147. data/lib/chef/resource/windows_uac.rb +3 -5
  148. data/lib/chef/resource/windows_update_settings.rb +259 -0
  149. data/lib/chef/resource/windows_user_privilege.rb +2 -2
  150. data/lib/chef/resource/windows_workgroup.rb +2 -2
  151. data/lib/chef/resource/yum_package.rb +11 -15
  152. data/lib/chef/resource/zypper_package.rb +4 -4
  153. data/lib/chef/resource/zypper_repository.rb +28 -8
  154. data/lib/chef/resource.rb +13 -17
  155. data/lib/chef/resource_inspector.rb +6 -2
  156. data/lib/chef/resource_reporter.rb +0 -1
  157. data/lib/chef/resources.rb +12 -1
  158. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  159. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  160. data/lib/chef/secret_fetcher/base.rb +76 -0
  161. data/lib/chef/secret_fetcher/example.rb +46 -0
  162. data/lib/chef/secret_fetcher.rb +55 -0
  163. data/lib/chef/version.rb +1 -1
  164. data/spec/functional/mixin/from_file_spec.rb +1 -1
  165. data/spec/functional/resource/windows_hostname_spec.rb +91 -0
  166. data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
  167. data/spec/integration/compliance/compliance_spec.rb +1 -0
  168. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  169. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  170. data/spec/support/shared/unit/provider/file.rb +2 -8
  171. data/spec/unit/compliance/runner_spec.rb +46 -2
  172. data/spec/unit/cookbook_version_spec.rb +52 -0
  173. data/spec/unit/data_collector_spec.rb +47 -1
  174. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  175. data/spec/unit/dsl/secret_spec.rb +71 -0
  176. data/spec/unit/formatters/doc_spec.rb +1 -1
  177. data/spec/unit/handler_spec.rb +8 -2
  178. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  179. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  180. data/spec/unit/provider/apt_update_spec.rb +3 -1
  181. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  182. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  183. data/spec/unit/provider/zypper_repository_spec.rb +3 -10
  184. data/spec/unit/provider_spec.rb +23 -0
  185. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  186. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  187. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  188. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  189. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  190. data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
  191. data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
  192. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  193. data/spec/unit/resource/zypper_repository_spec.rb +1 -1
  194. data/spec/unit/resource_spec.rb +19 -8
  195. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  196. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  197. data/spec/unit/secret_fetcher_spec.rb +82 -0
  198. metadata +55 -7
@@ -75,9 +75,7 @@ class Chef
75
75
  description: "The permission mode applied to all files created by the resource.",
76
76
  default: "0640"
77
77
 
78
- action :create do
79
- description "Create the RSA public key."
80
-
78
+ action :create, description: "Create the RSA public key file." do
81
79
  raise ArgumentError, "You cannot specify both 'private_key_path' and 'private_key_content' properties at the same time." if new_resource.private_key_path && new_resource.private_key_content
82
80
  raise ArgumentError, "You must specify the private key with either 'private_key_path' or 'private_key_content' properties." unless new_resource.private_key_path || new_resource.private_key_content
83
81
  raise "#{new_resource.private_key_path} not a valid private RSA key or password is invalid" unless priv_key_file_valid?((new_resource.private_key_path || new_resource.private_key_content), new_resource.private_key_pass)
@@ -151,15 +151,12 @@ class Chef
151
151
  description: "The number of days before the expiry. The certificate will be automatically renewed when the value is reached.",
152
152
  introduced: "15.7"
153
153
 
154
- action :create do
155
- description "Generate a certificate"
156
-
154
+ action :create, description: "Generate a certificate file." do
157
155
  file new_resource.path do
158
156
  action :create_if_missing
159
157
  owner new_resource.owner unless new_resource.owner.nil?
160
158
  group new_resource.group unless new_resource.group.nil?
161
159
  mode new_resource.mode unless new_resource.mode.nil?
162
- sensitive true
163
160
  content cert.to_pem
164
161
  end
165
162
 
@@ -90,9 +90,7 @@ class Chef
90
90
  property :mode, [Integer, String],
91
91
  description: "The permission mode of the CRL file."
92
92
 
93
- action :create do
94
- description "Create the CRL file."
95
-
93
+ action :create, description: "Create the certificate revocation list (CRL) file." do
96
94
  file new_resource.path do
97
95
  owner new_resource.owner unless new_resource.owner.nil?
98
96
  group new_resource.group unless new_resource.group.nil?
@@ -119,9 +119,7 @@ class Chef
119
119
  equal_to: %w{secp384r1 secp521r1 prime256v1}, default: "prime256v1",
120
120
  description: "The desired curve of the generated key (if key_type is equal to `ec`). Run `openssl ecparam -list_curves` to see available options."
121
121
 
122
- action :create do
123
- description "Generate a certificate request."
124
-
122
+ action :create, description: "Generate a certificate request file." do
125
123
  unless ::File.exist? new_resource.path
126
124
  converge_by("Create CSR #{@new_resource}") do
127
125
  file new_resource.path do
@@ -51,7 +51,7 @@ class Chef
51
51
  'PayloadOrganization' => 'Chef',
52
52
  'PayloadVersion' => 1,
53
53
  'PayloadDisplayName' => 'Screensaver Settings',
54
- 'PayloadContent'=> [
54
+ 'PayloadContent' => [
55
55
  {
56
56
  'PayloadType' => 'com.apple.ManagedClient.preferences',
57
57
  'PayloadVersion' => 1,
@@ -172,7 +172,7 @@ class Chef
172
172
  end
173
173
  end
174
174
 
175
- action :install do
175
+ action :install, description: "Install the specified configuration profile." do
176
176
  unless profile_installed?
177
177
  converge_by("install profile #{new_profile_identifier}") do
178
178
  profile_path = write_profile_to_disk
@@ -182,7 +182,7 @@ class Chef
182
182
  end
183
183
  end
184
184
 
185
- action :remove do
185
+ action :remove, description: "Remove the specified configuration profile." do
186
186
  # Clean up profile after removing it
187
187
  if profile_installed?
188
188
  converge_by("remove profile #{new_profile_identifier}") do
@@ -81,7 +81,7 @@ class Chef
81
81
  group file_group_cmd.stdout.chomp
82
82
  end
83
83
 
84
- action :set do
84
+ action :set, description: "Set a value in a plist file." do
85
85
  converge_if_changed :path do
86
86
  converge_by "create new plist: '#{new_resource.path}'" do
87
87
  file new_resource.path do
@@ -70,8 +70,7 @@ class Chef
70
70
  script_publish_location status["script_publish_location"]
71
71
  end
72
72
 
73
- action :register do
74
- description "Registers and updates the powershell package source."
73
+ action :register, description: "Registers and updates the PowerShell package source." do
75
74
  # TODO: Ensure package provider is installed?
76
75
  if psrepository_cmdlet_appropriate?
77
76
  if package_source_exists?
@@ -104,8 +103,7 @@ class Chef
104
103
  end
105
104
  end
106
105
 
107
- action :unregister do
108
- description "Unregisters the powershell package source."
106
+ action :unregister, description: "Unregisters the PowerShell package source." do
109
107
  if package_source_exists?
110
108
  unregister_cmd = "Get-PackageSource -Name '#{new_resource.source_name}' | Unregister-PackageSource"
111
109
  converge_by("unregister source: #{new_resource.source_name}") do
@@ -33,6 +33,41 @@ class Chef
33
33
  " immediate notifications. Delayed notifications produce unintuitive and"\
34
34
  " probably undesired results."
35
35
  introduced "12.0"
36
+ examples <<~DOC
37
+ **Reboot a node immediately**
38
+
39
+ ```ruby
40
+ reboot 'now' do
41
+ action :nothing
42
+ reason 'Cannot continue Chef run without a reboot.'
43
+ delay_mins 2
44
+ end
45
+
46
+ execute 'foo' do
47
+ command '...'
48
+ notifies :reboot_now, 'reboot[now]', :immediately
49
+ end
50
+ ```
51
+
52
+ **Reboot a node at the end of a Chef Infra Client run**
53
+
54
+ ```ruby
55
+ reboot 'app_requires_reboot' do
56
+ action :request_reboot
57
+ reason 'Need to reboot when the run completes successfully.'
58
+ delay_mins 5
59
+ end
60
+ ```
61
+
62
+ **Cancel a reboot**
63
+
64
+ ```ruby
65
+ reboot 'cancel_reboot_request' do
66
+ action :cancel
67
+ reason 'Cancel a previous end-of-run reboot request.'
68
+ end
69
+ ```
70
+ DOC
36
71
 
37
72
  property :reason, String,
38
73
  description: "A string that describes the reboot action.",
@@ -42,18 +77,14 @@ class Chef
42
77
  description: "The amount of time (in minutes) to delay a reboot request.",
43
78
  default: 0
44
79
 
45
- action :request_reboot do
46
- description "Reboot a node at the end of a chef-client run."
47
-
80
+ action :request_reboot, description: "Reboot a node at the end of a #{ChefUtils::Dist::Infra::PRODUCT} run." do
48
81
  converge_by("request a system reboot to occur if the run succeeds") do
49
82
  logger.warn "Reboot requested:'#{new_resource.name}'"
50
83
  request_reboot
51
84
  end
52
85
  end
53
86
 
54
- action :reboot_now do
55
- description "Reboot a node so that the chef-client may continue the installation process."
56
-
87
+ action :reboot_now, description: "Reboot a node so that the #{ChefUtils::Dist::Infra::PRODUCT} may continue the installation process." do
57
88
  converge_by("rebooting the system immediately") do
58
89
  logger.warn "Rebooting system immediately, requested by '#{new_resource.name}'"
59
90
  request_reboot
@@ -61,9 +92,7 @@ class Chef
61
92
  end
62
93
  end
63
94
 
64
- action :cancel do
65
- description "Cancel a pending reboot request."
66
-
95
+ action :cancel, description: "Cancel a pending reboot request." do
67
96
  converge_by("cancel any existing end-of-run reboot request") do
68
97
  logger.warn "Reboot canceled: '#{new_resource.name}'"
69
98
  node.run_context.cancel_reboot
@@ -71,7 +71,7 @@ class Chef
71
71
  desired_state: false
72
72
 
73
73
  property :files_group, [String, Integer],
74
- description: "Configure group permissions for files. A string or ID that identifies the group owner by group name, including fully qualified group names such as domain\\group or group@domain. If this value is not specified, existing groups remain unchanged and new group assignments use the default POSIX group (if available).",
74
+ description: "Configure group permissions for files. A string or ID that identifies the group owner by group name, including fully qualified group names such as `domain\\group` or `group@domain`. If this value is not specified, existing groups remain unchanged and new group assignments use the default POSIX group (if available).",
75
75
  regex: Chef::Config[:group_valid_regex]
76
76
 
77
77
  property :files_mode, [String, Integer, nil],
@@ -80,7 +80,7 @@ class Chef
80
80
  regex: /^\d{3,4}$/, default: lazy { 0644 unless Chef::Platform.windows? }
81
81
 
82
82
  property :files_owner, [String, Integer],
83
- description: "Configure owner permissions for files. A string or ID that identifies the group owner by user name, including fully qualified user names such as domain\\user or user@domain. If this value is not specified, existing owners remain unchanged and new owner assignments use the current user (when necessary).",
83
+ description: "Configure owner permissions for files. A string or ID that identifies the group owner by user name, including fully qualified user names such as `domain\\user` or `user@domain`. If this value is not specified, existing owners remain unchanged and new owner assignments use the current user (when necessary).",
84
84
  regex: Chef::Config[:user_valid_regex]
85
85
  end
86
86
  end
@@ -85,7 +85,7 @@ class Chef
85
85
  end
86
86
 
87
87
  property :use_etag, [ TrueClass, FalseClass ], default: true,
88
- description: "Enable ETag headers. Set to false to disable ETag headers. To use this setting, `use_conditional_get` must also be set to true."
88
+ description: "Enable ETag headers. Set to `false` to disable ETag headers. To use this setting, `use_conditional_get` must also be set to true."
89
89
 
90
90
  alias :use_etags :use_etag
91
91
 
@@ -46,8 +46,6 @@ class Chef
46
46
  name_property: true
47
47
 
48
48
  action :install, description: "Install a package for a specific errata ID." do
49
- description "Installs a package for a specific errata ID."
50
-
51
49
  execute "Install errata packages for #{new_resource.errata_id}" do
52
50
  command "#{package_manager_command} update --advisory #{new_resource.errata_id} -y"
53
51
  default_env true
@@ -42,11 +42,7 @@ class Chef
42
42
  name_property: true
43
43
 
44
44
  action :install, description: "Install all packages of the specified errata level." do
45
- description "Install all packages of the specified errata level."
46
-
47
- if rhel6?
48
- yum_package "yum-plugin-security"
49
- end
45
+ yum_package "yum-plugin-security" if rhel6?
50
46
 
51
47
  execute "Install any #{new_resource.errata_level} errata" do
52
48
  command "#{package_manager_command} update --sec-severity=#{new_resource.errata_level.capitalize} -y"
@@ -26,6 +26,21 @@ class Chef
26
26
 
27
27
  description "Use the **rhsm_repo** resource to enable or disable Red Hat Subscription Manager repositories that are made available via attached subscriptions."
28
28
  introduced "14.0"
29
+ examples <<~DOC
30
+ **Enable an RHSM repository**
31
+
32
+ ```ruby
33
+ rhsm_repo 'rhel-7-server-extras-rpms'
34
+ ```
35
+
36
+ **Disable an RHSM repository**
37
+
38
+ ```ruby
39
+ rhsm_repo 'rhel-7-server-extras-rpms' do
40
+ action :disable
41
+ end
42
+ ```
43
+ DOC
29
44
 
30
45
  property :repo_name, String,
31
46
  description: "An optional property for specifying the repository name if it differs from the resource block's name.",
@@ -32,11 +32,11 @@ class Chef
32
32
  name_property: true
33
33
 
34
34
  action :attach, description: "Attach the node to a subscription pool." do
35
- execute "Attach subscription pool #{new_resource.pool_id}" do
36
- command "subscription-manager attach --pool=#{new_resource.pool_id}"
37
- default_env true
38
- action :run
39
- not_if { subscription_attached?(new_resource.pool_id) }
35
+ unless subscription_attached?(new_resource.pool_id)
36
+ converge_by("attach subscription pool #{new_resource.pool_id}") do
37
+ shell_out!("subscription-manager attach --pool=#{new_resource.pool_id}")
38
+ build_resource(:package, "rhsm_subscription-#{new_resource.pool_id}-flush_cache").run_action(:flush_cache)
39
+ end
40
40
  end
41
41
  end
42
42
 
@@ -29,6 +29,106 @@ class Chef
29
29
  provides :ruby_block, target_mode: true
30
30
 
31
31
  description "Use the **ruby_block** resource to execute Ruby code during a #{ChefUtils::Dist::Infra::PRODUCT} run. Ruby code in the `ruby_block` resource is evaluated with other resources during convergence, whereas Ruby code outside of a `ruby_block` resource is evaluated before other resources, as the recipe is compiled."
32
+ examples <<~'DOC'
33
+ **Reload Chef Infra Client configuration data**
34
+
35
+ ```ruby
36
+ ruby_block 'reload_client_config' do
37
+ block do
38
+ Chef::Config.from_file('/etc/chef/client.rb')
39
+ end
40
+ action :run
41
+ end
42
+ ```
43
+
44
+ **Run a block on a particular platform**
45
+
46
+ The following example shows how an if statement can be used with the `windows?` method in the Chef Infra Language to run code specific to Microsoft Windows. The code is defined using the ruby_block resource:
47
+
48
+ ```ruby
49
+ if windows?
50
+ ruby_block 'copy libmysql.dll into ruby path' do
51
+ block do
52
+ require 'fileutils'
53
+ FileUtils.cp "#{node['mysql']['client']['lib_dir']}\\libmysql.dll",
54
+ node['mysql']['client']['ruby_dir']
55
+ end
56
+ not_if { ::File.exist?("#{node['mysql']['client']['ruby_dir']}\\libmysql.dll") }
57
+ end
58
+ end
59
+ ```
60
+
61
+ **Stash a file in a data bag**
62
+
63
+ The following example shows how to use the ruby_block resource to stash a BitTorrent file in a data bag so that it can be distributed to nodes in the organization.
64
+
65
+ ```ruby
66
+ ruby_block 'share the torrent file' do
67
+ block do
68
+ f = File.open(node['bittorrent']['torrent'],'rb')
69
+ #read the .torrent file and base64 encode it
70
+ enc = Base64.encode64(f.read)
71
+ data = {
72
+ 'id'=>bittorrent_item_id(node['bittorrent']['file']),
73
+ 'seed'=>node.ipaddress,
74
+ 'torrent'=>enc
75
+ }
76
+ item = Chef::DataBagItem.new
77
+ item.data_bag('bittorrent')
78
+ item.raw_data = data
79
+ item.save
80
+ end
81
+ action :nothing
82
+ subscribes :create, "bittorrent_torrent[#{node['bittorrent']['torrent']}]", :immediately
83
+ end
84
+ ```
85
+
86
+ **Update the /etc/hosts file**
87
+
88
+ The following example shows how the ruby_block resource can be used to update the /etc/hosts file:
89
+
90
+ ```ruby
91
+ ruby_block 'edit etc hosts' do
92
+ block do
93
+ rc = Chef::Util::FileEdit.new('/etc/hosts')
94
+ rc.search_file_replace_line(/^127\.0\.0\.1 localhost$/,
95
+ '127.0.0.1 #{new_fqdn} #{new_hostname} localhost')
96
+ rc.write_file
97
+ end
98
+ end
99
+ ```
100
+
101
+ **Set environment variables**
102
+
103
+ The following example shows how to use variables within a Ruby block to set environment variables using rbenv.
104
+
105
+ ```ruby
106
+ node.override[:rbenv][:root] = rbenv_root
107
+ node.override[:ruby_build][:bin_path] = rbenv_binary_path
108
+
109
+ ruby_block 'initialize' do
110
+ block do
111
+ ENV['RBENV_ROOT'] = node[:rbenv][:root]
112
+ ENV['PATH'] = "#{node[:rbenv][:root]}/bin:#{node[:ruby_build][:bin_path]}:#{ENV['PATH']}"
113
+ end
114
+ end
115
+ ```
116
+
117
+ **Call methods in a gem**
118
+
119
+ The following example shows how to call methods in gems not shipped in Chef Infra Client
120
+
121
+ ```ruby
122
+ chef_gem 'mongodb'
123
+
124
+ ruby_block 'config_replicaset' do
125
+ block do
126
+ MongoDB.configure_replicaset(node, replicaset_name, rs_nodes)
127
+ end
128
+ action :run
129
+ end
130
+ ```
131
+ DOC
32
132
 
33
133
  default_action :run
34
134
  allowed_actions :create, :run
@@ -28,7 +28,7 @@ class Chef
28
28
 
29
29
  provides :subversion
30
30
 
31
- description "Use the **subversion** resource to manage source control resources that exist in a Subversion repository."
31
+ description "Use the **subversion** resource to manage source control resources that exist in a Subversion repository. Warning: The subversion resource has known bugs and may not work as expected. For more information see Chef GitHub issues, particularly [#4050](https://github.com/chef/chef/issues/4050) and [#4257](https://github.com/chef/chef/issues/4257)."
32
32
  examples <<~DOC
33
33
  **Get the latest version of an application**
34
34
 
@@ -75,7 +75,8 @@ class Chef
75
75
 
76
76
  property :group, [String, Integer],
77
77
  description: "The file group for the ssh_known_hosts file.",
78
- default: lazy { node["root_group"] }
78
+ default: lazy { node["root_group"] },
79
+ default_description: "The root user's group depending on platform."
79
80
 
80
81
  property :hash_entries, [TrueClass, FalseClass],
81
82
  description: "Hash the hostname and addresses in the ssh_known_hosts file for privacy.",
@@ -85,9 +86,7 @@ class Chef
85
86
  description: "The location of the ssh known hosts file. Change this to set a known host file for a particular user.",
86
87
  default: "/etc/ssh/ssh_known_hosts"
87
88
 
88
- action :create do
89
- description "Create an entry in the ssh_known_hosts file."
90
-
89
+ action :create, description: "Create an entry in the ssh_known_hosts file." do
91
90
  key =
92
91
  if new_resource.key
93
92
  hoststr = (new_resource.port != 22) ? "[#{new_resource.host}]:#{new_resource.port}" : new_resource.host
@@ -129,9 +128,7 @@ class Chef
129
128
  end
130
129
 
131
130
  # all this does is send an immediate run_action(:create) to the template resource
132
- action :flush do
133
- description "Immediately flush the entries to the config file. Without this the actual writing of the file is delayed in the #{ChefUtils::Dist::Infra::PRODUCT} run so all entries can be accumulated before writing the file out."
134
-
131
+ action :flush, description: "Immediately flush the entries to the config file. Without this the actual writing of the file is delayed in the #{ChefUtils::Dist::Infra::PRODUCT} run so all entries can be accumulated before writing the file out." do
135
132
  with_run_context :root do
136
133
  # if you haven't ever called ssh_known_hosts_entry before you're definitely doing it wrong so we blow up hard.
137
134
  find_resource!(:template, "update ssh known hosts file #{new_resource.file_location}").run_action(:create)
@@ -170,9 +170,7 @@ class Chef
170
170
  end
171
171
  end
172
172
 
173
- action :create do
174
- description "Create a single sudoers config in the sudoers.d directory"
175
-
173
+ action :create, description: "Create a single sudoers configuration file in the `sudoers.d` directory." do
176
174
  validate_properties
177
175
 
178
176
  if docker? # don't even put this into resource collection unless we're in docker
@@ -230,9 +228,7 @@ class Chef
230
228
  end
231
229
 
232
230
  # Removes a user from the sudoers group
233
- action :delete do
234
- description "Remove a sudoers config from the sudoers.d directory"
235
-
231
+ action :delete, description: "Remove a sudoers configuration file from the `sudoers.d` directory." do
236
232
  file "#{new_resource.config_prefix}/sudoers.d/#{new_resource.filename}" do
237
233
  action :delete
238
234
  end