chef 17.2.29-universal-mingw32 → 17.5.22-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -5
  3. data/chef.gemspec +3 -0
  4. data/lib/chef/application/base.rb +11 -1
  5. data/lib/chef/application.rb +3 -1
  6. data/lib/chef/client.rb +2 -3
  7. data/lib/chef/compliance/default_attributes.rb +5 -3
  8. data/lib/chef/compliance/input.rb +115 -0
  9. data/lib/chef/compliance/input_collection.rb +139 -0
  10. data/lib/chef/compliance/profile.rb +122 -0
  11. data/lib/chef/compliance/profile_collection.rb +109 -0
  12. data/lib/chef/compliance/reporter/automate.rb +1 -1
  13. data/lib/chef/compliance/runner.rb +62 -6
  14. data/lib/chef/compliance/waiver.rb +115 -0
  15. data/lib/chef/compliance/waiver_collection.rb +143 -0
  16. data/lib/chef/data_bag.rb +1 -2
  17. data/lib/chef/data_bag_item.rb +1 -2
  18. data/lib/chef/deprecated.rb +10 -4
  19. data/lib/chef/dsl/compliance.rb +38 -0
  20. data/lib/chef/dsl/reader_helpers.rb +51 -0
  21. data/lib/chef/dsl/recipe.rb +4 -2
  22. data/lib/chef/dsl/render_helpers.rb +44 -0
  23. data/lib/chef/dsl/secret.rb +62 -0
  24. data/lib/chef/dsl/toml.rb +116 -0
  25. data/lib/chef/dsl/universal.rb +7 -0
  26. data/lib/chef/dsl.rb +1 -0
  27. data/lib/chef/event_dispatch/base.rb +44 -2
  28. data/lib/chef/exceptions.rb +20 -0
  29. data/lib/chef/formatters/doc.rb +60 -13
  30. data/lib/chef/formatters/error_mapper.rb +2 -2
  31. data/lib/chef/formatters/minimal.rb +6 -5
  32. data/lib/chef/handler/slow_report.rb +1 -1
  33. data/lib/chef/http/basic_client.rb +15 -7
  34. data/lib/chef/http.rb +12 -8
  35. data/lib/chef/json_compat.rb +1 -1
  36. data/lib/chef/policy_builder/policyfile.rb +88 -45
  37. data/lib/chef/provider/execute.rb +1 -1
  38. data/lib/chef/provider/file.rb +4 -2
  39. data/lib/chef/provider/group/dscl.rb +1 -1
  40. data/lib/chef/provider/launchd.rb +6 -6
  41. data/lib/chef/provider/link.rb +2 -2
  42. data/lib/chef/provider/lwrp_base.rb +1 -1
  43. data/lib/chef/provider/package/habitat.rb +168 -0
  44. data/lib/chef/provider/package/powershell.rb +5 -0
  45. data/lib/chef/provider/registry_key.rb +3 -2
  46. data/lib/chef/provider/remote_file/http.rb +1 -1
  47. data/lib/chef/provider/subversion.rb +4 -4
  48. data/lib/chef/provider/support/yum_repo.erb +1 -1
  49. data/lib/chef/provider/systemd_unit.rb +17 -16
  50. data/lib/chef/provider/template.rb +1 -1
  51. data/lib/chef/provider/user/mac.rb +3 -3
  52. data/lib/chef/provider/yum_repository.rb +27 -43
  53. data/lib/chef/provider/zypper_repository.rb +3 -3
  54. data/lib/chef/provider.rb +26 -1
  55. data/lib/chef/provider_resolver.rb +8 -2
  56. data/lib/chef/providers.rb +1 -0
  57. data/lib/chef/resource/archive_file.rb +17 -14
  58. data/lib/chef/resource/chef_client_config.rb +7 -2
  59. data/lib/chef/resource/chef_client_cron.rb +1 -1
  60. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  61. data/lib/chef/resource/chef_client_scheduled_task.rb +46 -3
  62. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -1
  63. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  64. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  65. data/lib/chef/resource/chocolatey_config.rb +13 -13
  66. data/lib/chef/resource/dsc_resource.rb +1 -1
  67. data/lib/chef/resource/execute.rb +5 -5
  68. data/lib/chef/resource/file/verification/json.rb +50 -0
  69. data/lib/chef/resource/file/verification/yaml.rb +52 -0
  70. data/lib/chef/resource/gem_package.rb +2 -1
  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 +1 -1
  81. data/lib/chef/resource/inspec_input.rb +128 -0
  82. data/lib/chef/resource/inspec_waiver.rb +185 -0
  83. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  84. data/lib/chef/resource/launchd.rb +3 -3
  85. data/lib/chef/resource/lwrp_base.rb +1 -1
  86. data/lib/chef/resource/mount.rb +1 -1
  87. data/lib/chef/resource/registry_key.rb +36 -48
  88. data/lib/chef/resource/remote_file.rb +99 -3
  89. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  90. data/lib/chef/resource/ruby_block.rb +100 -0
  91. data/lib/chef/resource/scm/subversion.rb +1 -1
  92. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  93. data/lib/chef/resource/support/client.erb +8 -1
  94. data/lib/chef/resource/support/sup.toml.erb +179 -0
  95. data/lib/chef/resource/sysctl.rb +2 -2
  96. data/lib/chef/resource/systemd_unit.rb +3 -3
  97. data/lib/chef/resource/timezone.rb +2 -2
  98. data/lib/chef/resource/user_ulimit.rb +1 -0
  99. data/lib/chef/resource/windows_defender.rb +163 -0
  100. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  101. data/lib/chef/resource/windows_printer.rb +78 -44
  102. data/lib/chef/resource/windows_printer_port.rb +1 -1
  103. data/lib/chef/resource/windows_uac.rb +3 -1
  104. data/lib/chef/resource/windows_update_settings.rb +259 -0
  105. data/lib/chef/resource/windows_user_privilege.rb +1 -1
  106. data/lib/chef/resource/yum_package.rb +1 -5
  107. data/lib/chef/resource.rb +13 -17
  108. data/lib/chef/resource_inspector.rb +6 -2
  109. data/lib/chef/resources.rb +14 -1
  110. data/lib/chef/run_context/cookbook_compiler.rb +112 -28
  111. data/lib/chef/run_context.rb +31 -1
  112. data/lib/chef/secret_fetcher/akeyless_vault.rb +57 -0
  113. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  114. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  115. data/lib/chef/secret_fetcher/base.rb +76 -0
  116. data/lib/chef/secret_fetcher/example.rb +46 -0
  117. data/lib/chef/secret_fetcher/hashi_vault.rb +100 -0
  118. data/lib/chef/secret_fetcher.rb +61 -0
  119. data/lib/chef/version.rb +1 -1
  120. data/spec/data/archive_file/test_archive.tar.gz +0 -0
  121. data/spec/functional/mixin/from_file_spec.rb +1 -1
  122. data/spec/functional/resource/archive_file_spec.rb +87 -0
  123. data/spec/functional/resource/group_spec.rb +5 -1
  124. data/spec/functional/resource/link_spec.rb +8 -0
  125. data/spec/integration/compliance/compliance_spec.rb +61 -0
  126. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  127. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  128. data/spec/spec_helper.rb +3 -0
  129. data/spec/support/platform_helpers.rb +4 -0
  130. data/spec/support/ruby_installer.rb +51 -0
  131. data/spec/support/shared/unit/provider/file.rb +2 -8
  132. data/spec/unit/compliance/input_spec.rb +104 -0
  133. data/spec/unit/compliance/profile_spec.rb +120 -0
  134. data/spec/unit/compliance/runner_spec.rb +46 -2
  135. data/spec/unit/compliance/waiver_spec.rb +104 -0
  136. data/spec/unit/data_bag_item_spec.rb +2 -2
  137. data/spec/unit/data_bag_spec.rb +1 -1
  138. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  139. data/spec/unit/dsl/secret_spec.rb +71 -0
  140. data/spec/unit/formatters/doc_spec.rb +1 -1
  141. data/spec/unit/http/basic_client_spec.rb +30 -0
  142. data/spec/unit/http_spec.rb +8 -2
  143. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  144. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  145. data/spec/unit/provider/apt_update_spec.rb +3 -1
  146. data/spec/unit/provider/link_spec.rb +13 -7
  147. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  148. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  149. data/spec/unit/provider/remote_file/http_spec.rb +10 -0
  150. data/spec/unit/provider/template_spec.rb +2 -2
  151. data/spec/unit/provider_spec.rb +23 -0
  152. data/spec/unit/resource/archive_file_spec.rb +414 -3
  153. data/spec/unit/resource/chef_client_scheduled_task_spec.rb +69 -0
  154. data/spec/unit/resource/file/verification/json_spec.rb +72 -0
  155. data/spec/unit/resource/file/verification/yaml_spec.rb +67 -0
  156. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  157. data/spec/unit/resource/inspec_input_spec.rb +300 -0
  158. data/spec/unit/resource/inspec_waiver_spec.rb +312 -0
  159. data/spec/unit/resource/mount_spec.rb +10 -0
  160. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  161. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  162. data/spec/unit/resource/user_ulimit_spec.rb +14 -1
  163. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  164. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  165. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  166. data/spec/unit/resource_spec.rb +19 -8
  167. data/spec/unit/secret_fetcher/akeyless_vault_spec.rb +37 -0
  168. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  169. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  170. data/spec/unit/secret_fetcher/hashi_vault_spec.rb +80 -0
  171. data/spec/unit/secret_fetcher_spec.rb +82 -0
  172. data/tasks/rspec.rb +2 -1
  173. metadata +106 -7
@@ -22,6 +22,7 @@ require_relative "../resource/file"
22
22
  require_relative "../resource/file/verification/systemd_unit"
23
23
  require "iniparse"
24
24
  require "shellwords" unless defined?(Shellwords)
25
+ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
25
26
 
26
27
  class Chef
27
28
  class Provider
@@ -75,7 +76,7 @@ class Chef
75
76
  end
76
77
  end
77
78
 
78
- action :create do
79
+ action :create, description: "Create a systemd unit file, if it does not already exist." do
79
80
  if current_resource.content != new_resource.to_ini
80
81
  converge_by("creating unit: #{new_resource.unit_name}") do
81
82
  manage_unit_file(:create)
@@ -84,7 +85,7 @@ class Chef
84
85
  end
85
86
  end
86
87
 
87
- action :delete do
88
+ action :delete, description: "Delete a systemd unit file, if it exists." do
88
89
  if ::File.exist?(unit_path)
89
90
  converge_by("deleting unit: #{new_resource.unit_name}") do
90
91
  manage_unit_file(:delete)
@@ -93,19 +94,19 @@ class Chef
93
94
  end
94
95
  end
95
96
 
96
- action :preset do
97
+ action :preset, description: "Restore the preset '`enable`/`disable`' configuration for a systemd unit. *New in #{ChefUtils::Dist::Infra::PRODUCT} 14.0.*" do
97
98
  converge_by("restoring enable/disable preset configuration for unit: #{new_resource.unit_name}") do
98
99
  systemctl_execute!(:preset, new_resource.unit_name)
99
100
  end
100
101
  end
101
102
 
102
- action :revert do
103
+ action :revert, description: "Revert to a vendor's version of a systemd unit file. *New in #{ChefUtils::Dist::Infra::PRODUCT} 14.0.*" do
103
104
  converge_by("reverting to vendor version of unit: #{new_resource.unit_name}") do
104
105
  systemctl_execute!(:revert, new_resource.unit_name)
105
106
  end
106
107
  end
107
108
 
108
- action :enable do
109
+ action :enable, description: "Ensure the unit will be started after the next system boot." do
109
110
  if current_resource.static
110
111
  logger.debug("#{new_resource.unit_name} is a static unit, enabling is a NOP.")
111
112
  end
@@ -121,7 +122,7 @@ class Chef
121
122
  end
122
123
  end
123
124
 
124
- action :disable do
125
+ action :disable, description: "Ensure the unit will not be started after the next system boot." do
125
126
  if current_resource.static
126
127
  logger.debug("#{new_resource.unit_name} is a static unit, disabling is a NOP.")
127
128
  end
@@ -138,14 +139,14 @@ class Chef
138
139
  end
139
140
  end
140
141
 
141
- action :reenable do
142
+ action :reenable, description: "Reenable a unit file. *New in #{ChefUtils::Dist::Infra::PRODUCT} 14.0.*" do
142
143
  converge_by("reenabling unit: #{new_resource.unit_name}") do
143
144
  systemctl_execute!(:reenable, new_resource.unit_name)
144
145
  logger.info("#{new_resource} reenabled")
145
146
  end
146
147
  end
147
148
 
148
- action :mask do
149
+ action :mask, description: "Ensure the unit will not start, even to satisfy dependencies." do
149
150
  unless current_resource.masked
150
151
  converge_by("masking unit: #{new_resource.unit_name}") do
151
152
  systemctl_execute!(:mask, new_resource.unit_name)
@@ -154,7 +155,7 @@ class Chef
154
155
  end
155
156
  end
156
157
 
157
- action :unmask do
158
+ action :unmask, description: "Stop the unit from being masked and cause it to start as specified." do
158
159
  if current_resource.masked
159
160
  converge_by("unmasking unit: #{new_resource.unit_name}") do
160
161
  systemctl_execute!(:unmask, new_resource.unit_name)
@@ -163,7 +164,7 @@ class Chef
163
164
  end
164
165
  end
165
166
 
166
- action :start do
167
+ action :start, description: "Start a systemd unit." do
167
168
  unless current_resource.active
168
169
  converge_by("starting unit: #{new_resource.unit_name}") do
169
170
  systemctl_execute!(:start, new_resource.unit_name, default_env: false)
@@ -172,7 +173,7 @@ class Chef
172
173
  end
173
174
  end
174
175
 
175
- action :stop do
176
+ action :stop, description: "Stop a running systemd unit." do
176
177
  if current_resource.active
177
178
  converge_by("stopping unit: #{new_resource.unit_name}") do
178
179
  systemctl_execute!(:stop, new_resource.unit_name, default_env: false)
@@ -181,14 +182,14 @@ class Chef
181
182
  end
182
183
  end
183
184
 
184
- action :restart do
185
+ action :restart, description: "Restart a systemd unit." do
185
186
  converge_by("restarting unit: #{new_resource.unit_name}") do
186
187
  systemctl_execute!(:restart, new_resource.unit_name, default_env: false)
187
188
  logger.info("#{new_resource} restarted")
188
189
  end
189
190
  end
190
191
 
191
- action :reload do
192
+ action :reload, description: "Reload the configuration file for a systemd unit." do
192
193
  if current_resource.active
193
194
  converge_by("reloading unit: #{new_resource.unit_name}") do
194
195
  systemctl_execute!(:reload, new_resource.unit_name, default_env: false)
@@ -199,21 +200,21 @@ class Chef
199
200
  end
200
201
  end
201
202
 
202
- action :try_restart do
203
+ action :try_restart, description: "Try to restart a systemd unit if the unit is running." do
203
204
  converge_by("try-restarting unit: #{new_resource.unit_name}") do
204
205
  systemctl_execute!("try-restart", new_resource.unit_name, default_env: false)
205
206
  logger.info("#{new_resource} try-restarted")
206
207
  end
207
208
  end
208
209
 
209
- action :reload_or_restart do
210
+ action :reload_or_restart, description: "For systemd units that are services, this action reloads the configuration of the service without restarting, if possible; otherwise, it will restart the service so the new configuration is applied." do
210
211
  converge_by("reload-or-restarting unit: #{new_resource.unit_name}") do
211
212
  systemctl_execute!("reload-or-restart", new_resource.unit_name, default_env: false)
212
213
  logger.info("#{new_resource} reload-or-restarted")
213
214
  end
214
215
  end
215
216
 
216
- action :reload_or_try_restart do
217
+ action :reload_or_try_restart, description: "For systemd units that are services, this action reloads the configuration of the service without restarting, if possible; otherwise, it will try to restart the service so the new configuration is applied." do
217
218
  converge_by("reload-or-try-restarting unit: #{new_resource.unit_name}") do
218
219
  systemctl_execute!("reload-or-try-restart", new_resource.unit_name, default_env: false)
219
220
  logger.info("#{new_resource} reload-or-try-restarted")
@@ -39,7 +39,7 @@ class Chef
39
39
  super
40
40
 
41
41
  requirements.assert(:create, :create_if_missing) do |a|
42
- a.assertion { ::File.exists?(content.template_location) }
42
+ a.assertion { ::File.exist?(content.template_location) }
43
43
  a.failure_message "Template source #{content.template_location} could not be found."
44
44
  a.whyrun "Template source #{content.template_location} does not exist. Assuming it would have been created."
45
45
  a.block_action!
@@ -28,7 +28,7 @@ class Chef
28
28
  class Provider
29
29
  class User
30
30
  # A macOS user provider that is compatible with default TCC restrictions
31
- # in macOS 10.14. See resource/user/mac_user.rb for complete description
31
+ # in macOS 10.14+. See resource/user/mac_user.rb for complete description
32
32
  # of the mac_user resource
33
33
  class MacUser < Chef::Provider::User
34
34
  include Chef::Mixin::Which
@@ -49,11 +49,11 @@ class Chef
49
49
  current_resource.uid(user_plist[:uid][0])
50
50
  current_resource.gid(user_plist[:gid][0])
51
51
  current_resource.home(user_plist[:home][0])
52
- current_resource.shell(user_plist[:shell][0])
52
+ current_resource.shell(user_plist[:shell]&.first) # use &.first since shell can be nil
53
53
  current_resource.comment(user_plist[:comment][0])
54
54
 
55
55
  if user_plist[:is_hidden]
56
- current_resource.hidden(user_plist[:is_hidden][0] == "1" ? true : false)
56
+ current_resource.hidden(user_plist[:is_hidden]&.first == "1" ? true : false) # when not hidden the value seems to be nil so &.first to handle that
57
57
  end
58
58
 
59
59
  shadow_hash = user_plist[:shadow_hash]
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  require_relative "../resource"
20
- require_relative "../dsl/declare_resource"
21
20
  require_relative "../mixin/which"
22
21
  require_relative "noop"
23
22
 
@@ -32,8 +31,8 @@ class Chef
32
31
 
33
32
  def load_current_resource; end
34
33
 
35
- action :create do
36
- declare_resource(:template, ::File.join(new_resource.reposdir, "#{new_resource.repositoryid}.repo")) do
34
+ action :create, description: "Create a repository based on the properties." do
35
+ template ::File.join(new_resource.reposdir, "#{new_resource.repositoryid}.repo") do
37
36
  if template_available?(new_resource.source)
38
37
  source new_resource.source
39
38
  else
@@ -46,72 +45,57 @@ class Chef
46
45
  if new_resource.make_cache
47
46
  notifies :run, "execute[yum clean metadata #{new_resource.repositoryid}]", :immediately if new_resource.clean_metadata || new_resource.clean_headers
48
47
  notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately
49
- notifies :create, "ruby_block[package-cache-reload-#{new_resource.repositoryid}]", :immediately
48
+ notifies :flush_cache, "package[package-cache-reload-#{new_resource.repositoryid}]", :immediately
50
49
  end
51
50
  end
52
51
 
53
- declare_resource(:execute, "yum clean metadata #{new_resource.repositoryid}") do
54
- command "yum clean metadata --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
55
- action :nothing
56
- end
52
+ # avoid extra logging if make_cache property isn't set
53
+ if new_resource.make_cache
54
+ execute "yum clean metadata #{new_resource.repositoryid}" do
55
+ command "yum clean metadata --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
56
+ action :nothing
57
+ end
57
58
 
58
- # get the metadata for this repo only
59
- declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do
60
- command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
61
- action :nothing
62
- only_if { new_resource.enabled }
63
- end
59
+ # get the metadata for this repo only
60
+ execute "yum-makecache-#{new_resource.repositoryid}" do
61
+ command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
62
+ action :nothing
63
+ only_if { new_resource.enabled }
64
+ end
64
65
 
65
- # reload internal Chef yum/dnf cache
66
- declare_resource(:ruby_block, "package-cache-reload-#{new_resource.repositoryid}") do
67
- if ( platform?("fedora") && node["platform_version"].to_i >= 22 ) ||
68
- ( platform_family?("rhel") && node["platform_version"].to_i >= 8 )
69
- block { Chef::Provider::Package::Dnf::PythonHelper.instance.restart }
70
- else
71
- block { Chef::Provider::Package::Yum::YumCache.instance.reload }
66
+ package "package-cache-reload-#{new_resource.repositoryid}" do
67
+ action :nothing
72
68
  end
73
- action :nothing
74
69
  end
75
70
  end
76
71
 
77
- action :delete do
72
+ action :delete, description: "Remove a repository." do
78
73
  # clean the repo cache first
79
- declare_resource(:execute, "yum clean all #{new_resource.repositoryid}") do
74
+ execute "yum clean all #{new_resource.repositoryid}" do
80
75
  command "yum clean all --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
81
76
  only_if "yum repolist all | grep -P '^#{new_resource.repositoryid}([ \t]|$)'"
82
77
  end
83
78
 
84
- declare_resource(:file, ::File.join(new_resource.reposdir, "#{new_resource.repositoryid}.repo")) do
79
+ file ::File.join(new_resource.reposdir, "#{new_resource.repositoryid}.repo") do
85
80
  action :delete
86
- notifies :create, "ruby_block[package-cache-reload-#{new_resource.repositoryid}]", :immediately
81
+ notifies :flush_cache, "package[package-cache-reload-#{new_resource.repositoryid}]", :immediately
87
82
  end
88
83
 
89
- declare_resource(:ruby_block, "package-cache-reload-#{new_resource.repositoryid}") do
90
- if ( platform?("fedora") && node["platform_version"].to_i >= 22 ) ||
91
- ( platform_family?("rhel") && node["platform_version"].to_i >= 8 )
92
- block { Chef::Provider::Package::Dnf::PythonHelper.instance.restart }
93
- else
94
- block { Chef::Provider::Package::Yum::YumCache.instance.reload }
95
- end
84
+ package "package-cache-reload-#{new_resource.repositoryid}" do
96
85
  action :nothing
97
86
  end
98
87
  end
99
88
 
100
- action :makecache do
101
- declare_resource(:execute, "yum-makecache-#{new_resource.repositoryid}") do
89
+ action :makecache, description: "Force the creation of the repository cache. This is also done automatically when a repository is updated." do
90
+ execute "yum-makecache-#{new_resource.repositoryid}" do
102
91
  command "yum -q -y makecache --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
103
92
  action :run
104
93
  only_if { new_resource.enabled }
94
+ notifies :flush_cache, "package[package-cache-reload-#{new_resource.repositoryid}]", :immediately
105
95
  end
106
96
 
107
- declare_resource(:ruby_block, "package-cache-reload-#{new_resource.repositoryid}") do
108
- if ( platform?("fedora") && node["platform_version"].to_i >= 22 ) ||
109
- ( platform_family?("rhel") && node["platform_version"].to_i >= 8 )
110
- block { Chef::Provider::Package::Dnf::PythonHelper.instance.restart }
111
- else
112
- block { Chef::Provider::Package::Yum::YumCache.instance.reload }
113
- end
114
- action :run
97
+ package "package-cache-reload-#{new_resource.repositoryid}" do
98
+ action :nothing
115
99
  end
116
100
  end
117
101
 
@@ -29,7 +29,7 @@ class Chef
29
29
 
30
30
  def load_current_resource; end
31
31
 
32
- action :create do
32
+ action :create, description: "Add a new Zypper repository." do
33
33
  if new_resource.gpgautoimportkeys
34
34
  install_gpg_keys(new_resource.gpgkey)
35
35
  else
@@ -50,13 +50,13 @@ class Chef
50
50
  end
51
51
  end
52
52
 
53
- action :delete do
53
+ action :delete, description: "Remove a Zypper repository." do
54
54
  execute "zypper --quiet --non-interactive removerepo #{escaped_repo_name}" do
55
55
  only_if "zypper --quiet lr #{escaped_repo_name}"
56
56
  end
57
57
  end
58
58
 
59
- action :refresh do
59
+ action :refresh, description: "Refresh Zypper repository." do
60
60
  execute "zypper --quiet --non-interactive refresh --force #{escaped_repo_name}" do
61
61
  only_if "zypper --quiet lr #{escaped_repo_name}"
62
62
  end
data/lib/chef/provider.rb CHANGED
@@ -57,10 +57,12 @@ class Chef
57
57
  #
58
58
  # @since 13.0
59
59
  # @param name [String, Symbol] Name of the action to define.
60
+ # @param description [String] description of the action
60
61
  # @param block [Proc] Body of the action.
61
62
  #
62
63
  # @return [void]
63
- def self.action(name, &block)
64
+ def self.action(name, description: nil, &block)
65
+ action_descriptions[name.to_sym] = description unless description.nil?
64
66
  # We need the block directly in a method so that `return` works.
65
67
  define_method("compile_action_#{name}", &block)
66
68
  class_eval <<-EOM
@@ -70,6 +72,29 @@ class Chef
70
72
  EOM
71
73
  end
72
74
 
75
+ # Return the hash of action descriptions defined for
76
+ # the provider class.
77
+ #
78
+ # @return [Hash] hash of [Symbol] => [String] containing
79
+ # any provided action descriptions.
80
+ def self.action_descriptions
81
+ @action_descriptions ||= {}
82
+ end
83
+
84
+ # Retrieve the description for a provider's action, if
85
+ # any description has been included in the definition.
86
+ #
87
+ # @param action [Symbol,String] the action name
88
+ # @return [String] the description of the action provided, or nil if no description
89
+ # was defined
90
+ def self.action_description(action)
91
+ description = action_descriptions[action.to_sym]
92
+ if description.nil? && superclass.respond_to?(:action_description)
93
+ description = superclass.action_description(action)
94
+ end
95
+ description
96
+ end
97
+
73
98
  # Deprecation stub for the old use_inline_resources mode.
74
99
  #
75
100
  # @return [void]
@@ -57,10 +57,16 @@ class Chef
57
57
  end
58
58
 
59
59
  def resolve
60
- maybe_explicit_provider(resource) ||
60
+ resolved = maybe_explicit_provider(resource) ||
61
61
  maybe_custom_resource(resource) ||
62
- maybe_dynamic_provider_resolution(resource, action) ||
62
+ maybe_dynamic_provider_resolution(resource, action)
63
+
64
+ if resolved.nil?
65
+ raise(Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource}") if node.nil?
66
+
63
67
  raise(Chef::Exceptions::ProviderNotFound, "Cannot find a provider for #{resource} on #{node["platform"]} version #{node["platform_version"]}")
68
+ end
69
+ resolved
64
70
  end
65
71
 
66
72
  # Does NOT call provides? on the resource (it is assumed this is being
@@ -74,6 +74,7 @@ require_relative "provider/package/cab"
74
74
  require_relative "provider/package/powershell"
75
75
  require_relative "provider/package/msu"
76
76
  require_relative "provider/package/snap"
77
+ require_relative "provider/package/habitat"
77
78
 
78
79
  require_relative "provider/service/arch"
79
80
  require_relative "provider/service/freebsd"
@@ -81,6 +81,11 @@ class Chef
81
81
  description: "Should the resource overwrite the destination file contents if they already exist? If set to `:auto` the date stamp of files within the archive will be compared to those on disk and disk contents will be overwritten if they differ. This may cause unintended consequences if disk date stamps are changed between runs, which will result in the files being overwritten during each client run. Make sure to properly test any change to this property.",
82
82
  default: false
83
83
 
84
+ property :strip_components, Integer,
85
+ description: "Remove the specified number of leading path elements. Pathnames with fewer elements will be silently skipped. This behaves similarly to tar's --strip-components command line argument.",
86
+ introduced: "17.5",
87
+ default: 0
88
+
84
89
  # backwards compatibility for the legacy cookbook names
85
90
  alias_method :extract_options, :options
86
91
  alias_method :extract_to, :destination
@@ -117,7 +122,7 @@ class Chef
117
122
 
118
123
  if new_resource.owner || new_resource.group
119
124
  converge_by("set owner of files extracted in #{new_resource.destination} to #{new_resource.owner}:#{new_resource.group}") do
120
- archive = Archive::Reader.open_filename(new_resource.path)
125
+ archive = Archive::Reader.open_filename(new_resource.path, nil, strip_components: new_resource.strip_components)
121
126
  archive.each_entry do |e|
122
127
  FileUtils.chown(new_resource.owner, new_resource.group, "#{new_resource.destination}/#{e.pathname}")
123
128
  end
@@ -160,18 +165,16 @@ class Chef
160
165
  # @return [Boolean]
161
166
  def archive_differs_from_disk?(src, dest)
162
167
  modified = false
163
- Dir.chdir(dest) do
164
- archive = Archive::Reader.open_filename(src)
165
- Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}")
166
- archive.each_entry do |e|
167
- pathname = ::File.expand_path(e.pathname)
168
- if ::File.exist?(pathname)
169
- Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
170
- modified = true unless ::File.mtime(pathname) == e.mtime
171
- else
172
- Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
173
- modified = true
174
- end
168
+ archive = Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components)
169
+ Chef::Log.trace("Beginning the comparison of file mtime between contents of #{src} and #{dest}")
170
+ archive.each_entry do |e|
171
+ pathname = ::File.expand_path(e.pathname, dest)
172
+ if ::File.exist?(pathname)
173
+ Chef::Log.trace("#{pathname} mtime is #{::File.mtime(pathname)} and archive is #{e.mtime}")
174
+ modified = true unless ::File.mtime(pathname) == e.mtime
175
+ else
176
+ Chef::Log.trace("#{pathname} doesn't exist on disk, but exists in the archive")
177
+ modified = true
175
178
  end
176
179
  end
177
180
  modified
@@ -189,7 +192,7 @@ class Chef
189
192
  flags = [options].flatten.map { |option| extract_option_map[option] }.compact.reduce(:|)
190
193
 
191
194
  Dir.chdir(dest) do
192
- archive = Archive::Reader.open_filename(src)
195
+ archive = Archive::Reader.open_filename(src, nil, strip_components: new_resource.strip_components)
193
196
 
194
197
  archive.each_entry do |e|
195
198
  archive.extract(e, flags.to_i)
@@ -29,7 +29,7 @@ class Chef
29
29
  examples <<~DOC
30
30
  **Bare minimum #{ChefUtils::Dist::Infra::PRODUCT} client.rb**:
31
31
 
32
- The absolute minimum configuration necessary for a node to communicate with the Infra Server is the URL of the Infra Server. All other configuration options either have values at the server side (Policyfiles, Roles, Environments, etc) or have default values determined at client startup.
32
+ The absolute minimum configuration necessary for a node to communicate with the #{ChefUtils::Dist::Server::PRODUCT} is the URL of the #{ChefUtils::Dist::Server::PRODUCT}. All other configuration options either have values at the server side (Policyfiles, Roles, Environments, etc) or have default values determined at client startup.
33
33
 
34
34
  ```ruby
35
35
  chef_client_config 'Create client.rb' do
@@ -184,6 +184,10 @@ class Chef
184
184
  coerce: proc { |x| x.map { |v| string_to_symbol(v).capitalize } },
185
185
  default: []
186
186
 
187
+ property :policy_persist_run_list, [true, false],
188
+ description: "Override run lists defined in a Policyfile with the `run_list` defined on the #{ChefUtils::Dist::Server::PRODUCT}.",
189
+ introduced: "17.3"
190
+
187
191
  property :minimal_ohai, [true, false],
188
192
  description: "Run a minimal set of Ohai plugins providing data necessary for the execution of #{ChefUtils::Dist::Infra::PRODUCT}'s built-in resources. Setting this to true will skip many large and time consuming data sets such as `cloud` or `packages`. Setting this this to true may break cookbooks that assume all Ohai data will be present."
189
193
 
@@ -277,7 +281,8 @@ class Chef
277
281
  report_handlers: format_handler(new_resource.report_handlers),
278
282
  ssl_verify_mode: new_resource.ssl_verify_mode,
279
283
  start_handlers: format_handler(new_resource.start_handlers),
280
- additional_config: new_resource.additional_config
284
+ additional_config: new_resource.additional_config,
285
+ policy_persist_run_list: new_resource.policy_persist_run_list
281
286
  )
282
287
  mode "0640"
283
288
  action :create
@@ -106,7 +106,7 @@ class Chef
106
106
  description: "The e-mail address to e-mail any cron task failures to."
107
107
 
108
108
  property :accept_chef_license, [true, false],
109
- description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement/>",
109
+ description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement>",
110
110
  default: false
111
111
 
112
112
  property :config_directory, String,
@@ -65,7 +65,7 @@ class Chef
65
65
  description: "A random number of seconds between 0 and X to add to interval so that all #{ChefUtils::Dist::Infra::CLIENT} commands don't execute at the same time."
66
66
 
67
67
  property :accept_chef_license, [true, false],
68
- description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement/>",
68
+ description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement>",
69
69
  default: false
70
70
 
71
71
  property :config_directory, String,
@@ -58,6 +58,14 @@ class Chef
58
58
  daemon_options ['-n audit_only']
59
59
  end
60
60
  ```
61
+
62
+ **Run #{ChefUtils::Dist::Infra::PRODUCT} with a persistent delay on every run calculated once, similar to how chef_client_cron resource works**:
63
+
64
+ ```ruby
65
+ chef_client_scheduled_task 'Run chef-client with persistent splay' do
66
+ use_consistent_splay true
67
+ end
68
+ ```
61
69
  DOC
62
70
 
63
71
  resource_name :chef_client_scheduled_task
@@ -87,7 +95,7 @@ class Chef
87
95
  default_description: "30 if frequency is 'minute', 1 otherwise"
88
96
 
89
97
  property :accept_chef_license, [true, false],
90
- description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement/>",
98
+ description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement>",
91
99
  default: false
92
100
 
93
101
  property :start_date, String,
@@ -104,6 +112,11 @@ class Chef
104
112
  description: "A random number of seconds between 0 and X to add to interval so that all #{ChefUtils::Dist::Infra::CLIENT} commands don't execute at the same time.",
105
113
  default: 300
106
114
 
115
+ property :use_consistent_splay, [true, false],
116
+ description: "Always use the same random splay amount for each node to ensure consistent frequencies between #{ChefUtils::Dist::Infra::CLIENT} execution.",
117
+ introduced: "17.5",
118
+ default: false
119
+
107
120
  property :run_on_battery, [true, false],
108
121
  description: "Run the #{ChefUtils::Dist::Infra::PRODUCT} task when the system is on batteries.",
109
122
  default: true
@@ -129,6 +142,11 @@ class Chef
129
142
  description: "An array of options to pass to the #{ChefUtils::Dist::Infra::CLIENT} command.",
130
143
  default: []
131
144
 
145
+ property :priority, Integer,
146
+ description: "Use to set Priority Levels range from 0 to 10.",
147
+ introduced: "17.5",
148
+ default: 7, callbacks: { "should be in range of 0 to 10" => proc { |v| v >= 0 && v <= 10 } }
149
+
132
150
  action :add, description: "Add a Windows Scheduled Task that runs #{ChefUtils::Dist::Infra::PRODUCT}." do
133
151
  # TODO: Replace this with a :create_if_missing action on directory when that exists
134
152
  unless Dir.exist?(new_resource.log_directory)
@@ -151,8 +169,9 @@ class Chef
151
169
  frequency_modifier new_resource.frequency_modifier if frequency_supports_frequency_modifier?
152
170
  start_time new_resource.start_time
153
171
  start_day new_resource.start_date unless new_resource.start_date.nil?
154
- random_delay new_resource.splay if frequency_supports_random_delay?
172
+ random_delay new_resource.splay if frequency_supports_random_delay? && !new_resource.use_consistent_splay
155
173
  disallow_start_if_on_batteries new_resource.splay unless new_resource.run_on_battery
174
+ priority new_resource.priority
156
175
  action %i{create enable}
157
176
  end
158
177
  end
@@ -173,7 +192,31 @@ class Chef
173
192
  # Fetch path of cmd.exe through environment variable comspec
174
193
  cmd_path = ENV["COMSPEC"]
175
194
 
176
- "#{cmd_path} /c \"#{client_cmd}\""
195
+ "#{cmd_path} /c \"#{consistent_splay_command}#{client_cmd}\""
196
+ end
197
+
198
+ #
199
+ # Generate a uniformly distributed unique number to sleep from 0 to the splay time
200
+ #
201
+ # @param [Integer] splay The number of seconds to splay
202
+ #
203
+ # @return [Integer]
204
+ #
205
+ def splay_sleep_time(splay)
206
+ seed = node["shard_seed"] || Digest::MD5.hexdigest(node.name).to_s.hex
207
+ random = Random.new(seed.to_i)
208
+ random.rand(splay)
209
+ end
210
+
211
+ #
212
+ # The consistent splay sleep time when use_consistent_splay is true.
213
+ #
214
+ # @return [NilClass,String] The prepended sleep command to run prior to executing the full command.
215
+ #
216
+ def consistent_splay_command
217
+ return unless new_resource.use_consistent_splay
218
+
219
+ "C:/windows/system32/windowspowershell/v1.0/powershell.exe Start-Sleep -s #{splay_sleep_time(new_resource.splay)} && "
177
220
  end
178
221
 
179
222
  #
@@ -75,7 +75,7 @@ class Chef
75
75
  default: "5min"
76
76
 
77
77
  property :accept_chef_license, [true, false],
78
- description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement/>",
78
+ description: "Accept the Chef Online Master License and Services Agreement. See <https://www.chef.io/online-master-agreement>",
79
79
  default: false
80
80
 
81
81
  property :run_on_battery, [true, false],
@@ -64,7 +64,7 @@ class Chef
64
64
  property :certificate, String, required: [:add],
65
65
  description: "The text of the certificate file including the BEGIN/END comment lines."
66
66
 
67
- action :add do
67
+ action :add, description: "Add a trusted certificate to #{ChefUtils::Dist::Infra::PRODUCT}'s trusted certificate directory" do
68
68
  unless ::Dir.exist?(Chef::Config[:trusted_certs_dir])
69
69
  directory Chef::Config[:trusted_certs_dir] do
70
70
  mode "0640"
@@ -78,7 +78,7 @@ class Chef
78
78
  end
79
79
  end
80
80
 
81
- action :remove do
81
+ action :remove, description: "Remove a trusted certificate from #{ChefUtils::Dist::Infra::PRODUCT}'s trusted certificate directory" do
82
82
  file cert_path do
83
83
  action :delete
84
84
  end
@@ -33,7 +33,7 @@ class Chef
33
33
  ```ruby
34
34
  chef_vault_secret 'foo' do
35
35
  data_bag 'bar'
36
- raw_data({'auth' => 'baz'})
36
+ raw_data({ 'auth' => 'baz' })
37
37
  admins 'jtimberman'
38
38
  search '*:*'
39
39
  end
@@ -45,7 +45,7 @@ class Chef
45
45
  chef_vault_secret 'root-password' do
46
46
  admins 'jtimberman,paulmooring'
47
47
  data_bag 'secrets'
48
- raw_data({'auth' => 'DoNotUseThisPasswordForRoot'})
48
+ raw_data({ 'auth' => 'DoNotUseThisPasswordForRoot' })
49
49
  search '*:*'
50
50
  end
51
51
  ```