chef 17.3.48 → 17.4.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/chef/application.rb +3 -1
  3. data/lib/chef/compliance/default_attributes.rb +5 -3
  4. data/lib/chef/compliance/runner.rb +15 -1
  5. data/lib/chef/dsl/secret.rb +3 -3
  6. data/lib/chef/exceptions.rb +0 -2
  7. data/lib/chef/formatters/error_mapper.rb +2 -2
  8. data/lib/chef/provider/execute.rb +1 -1
  9. data/lib/chef/provider/group/dscl.rb +1 -1
  10. data/lib/chef/provider/launchd.rb +6 -6
  11. data/lib/chef/provider/subversion.rb +4 -4
  12. data/lib/chef/provider/support/yum_repo.erb +1 -1
  13. data/lib/chef/provider/systemd_unit.rb +17 -16
  14. data/lib/chef/provider/user/mac.rb +3 -3
  15. data/lib/chef/provider/yum_repository.rb +27 -43
  16. data/lib/chef/provider/zypper_repository.rb +3 -3
  17. data/lib/chef/provider.rb +26 -1
  18. data/lib/chef/provider_resolver.rb +8 -2
  19. data/lib/chef/resource/homebrew_cask.rb +1 -1
  20. data/lib/chef/resource/inspec_waiver_file_entry.rb +2 -2
  21. data/lib/chef/resource/launchd.rb +3 -3
  22. data/lib/chef/resource/remote_file.rb +1 -1
  23. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  24. data/lib/chef/resource/ruby_block.rb +100 -0
  25. data/lib/chef/resource/scm/subversion.rb +1 -1
  26. data/lib/chef/resource/sysctl.rb +2 -2
  27. data/lib/chef/resource/systemd_unit.rb +3 -3
  28. data/lib/chef/resource/yum_package.rb +1 -5
  29. data/lib/chef/resource.rb +14 -18
  30. data/lib/chef/resource_inspector.rb +6 -2
  31. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +16 -4
  32. data/lib/chef/secret_fetcher/azure_key_vault.rb +31 -9
  33. data/lib/chef/secret_fetcher/base.rb +5 -1
  34. data/lib/chef/secret_fetcher.rb +5 -4
  35. data/lib/chef/version.rb +1 -1
  36. data/spec/integration/compliance/compliance_spec.rb +1 -0
  37. data/spec/integration/recipes/resource_action_spec.rb +2 -2
  38. data/spec/unit/compliance/runner_spec.rb +46 -2
  39. data/spec/unit/dsl/secret_spec.rb +8 -2
  40. data/spec/unit/provider_spec.rb +23 -0
  41. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  42. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  43. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  44. data/spec/unit/resource_spec.rb +19 -8
  45. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  46. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +23 -16
  47. data/spec/unit/secret_fetcher_spec.rb +9 -9
  48. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45a45627ed2995c171f44e97e524e17cdcc2b8a3c4566c6cba3e7e57a5810f71
4
- data.tar.gz: 5bbe7e7fecc35ddfddc730addb9a944a798ff252a239e433f6894228c9af6359
3
+ metadata.gz: c159fb85af31dd6bd19924a07f00bf9b95d0dfb1d88fb61a31715a9bdd3e96ec
4
+ data.tar.gz: 9a98b549790322419a603d451b8d0ad612cdff4e43b7ea7b902b14838dbf02ee
5
5
  SHA512:
6
- metadata.gz: 3ef336ebe43aa213491af9e263758101f040ee306537d8d3d0db4a6484fa33daf78c0a524525ee648688cfe9fa2c77d5163ce310d6977b85c0ccf761fcc763ba
7
- data.tar.gz: 554e9acfa53f9bc83a3b04cd9efb913b984bf9f69cb58b924a3ad9744fd2af8ff8bf42b6b495ba243ad71364d59ba433f6c440b9768c59aa3a7d9239948e2c7e
6
+ metadata.gz: 7ba002628326ef955c31a01fd28e799591100f09eae310a289de0edb8cc6d412f6db37b2af090dbb6eabdf5a1aa87456ff305d3f4c0b343a16832d227f560381
7
+ data.tar.gz: 1dedaff5d73ff603b322f11282deefc699091e89c0544bff43cb039bbb9627269d0f7e2e43fffd604dfd7d22042b51efa43b54789098ed8e8931da1f1bfc7601
@@ -377,7 +377,9 @@ class Chef
377
377
 
378
378
  Chef::FileCache.store("#{ChefUtils::Dist::Infra::SHORT}-stacktrace.out", chef_stacktrace_out)
379
379
  logger.fatal("Stacktrace dumped to #{Chef::FileCache.load("#{ChefUtils::Dist::Infra::SHORT}-stacktrace.out", false)}")
380
- logger.fatal("Please provide the contents of the stacktrace.out file if you file a bug report")
380
+ logger.fatal("---------------------------------------------------------------------------------------")
381
+ logger.fatal("PLEASE PROVIDE THE CONTENTS OF THE stacktrace.out FILE (above) IF YOU FILE A BUG REPORT")
382
+ logger.fatal("---------------------------------------------------------------------------------------")
381
383
  if Chef::Config[:always_dump_stacktrace]
382
384
  logger.fatal(message)
383
385
  else
@@ -28,7 +28,7 @@ class Chef
28
28
  # Controls what is done with the resulting report after the Chef InSpec run.
29
29
  # Accepts a single string value or an array of multiple values.
30
30
  # Accepted values: 'chef-server-automate', 'chef-automate', 'json-file', 'audit-enforcer', 'cli'
31
- "reporter" => %w{json-file cli},
31
+ "reporter" => "cli",
32
32
 
33
33
  # Controls if Chef InSpec profiles should be fetched from Chef Automate or Chef Infra Server
34
34
  # in addition to the default fetch locations provided by Chef Inspec.
@@ -47,8 +47,10 @@ class Chef
47
47
  "profiles" => {},
48
48
 
49
49
  # Extra inputs passed to Chef InSpec to allow finer-grained control over behavior.
50
- # These are mapped to Chef InSpec's inputs, but are named attributes here for legacy reasons.
51
50
  # See Chef Inspec's documentation for more information: https://docs.chef.io/inspec/inputs/
51
+ "inputs" => {},
52
+
53
+ # Legacy alias for inputs
52
54
  "attributes" => {},
53
55
 
54
56
  # A string path or an array of paths to Chef InSpec waiver files.
@@ -88,7 +90,7 @@ class Chef
88
90
 
89
91
  # If enabled, a hash representation of the Chef Infra node object will be sent to Chef InSpec in an input
90
92
  # named `chef_node`.
91
- "chef_node_attribute_enabled" => false,
93
+ "chef_node_attribute_enabled" => true,
92
94
 
93
95
  # Should the built-in compliance phase run. True and false force the behavior. Nil does magic based on if you have
94
96
  # profiles defined but do not have the audit cookbook enabled.
@@ -113,8 +113,17 @@ class Chef
113
113
  logger.info "Chef Infra Compliance Phase Complete"
114
114
  end
115
115
 
116
+ def inputs_from_attributes
117
+ if !node["audit"]["inputs"].empty?
118
+ node["audit"]["inputs"].to_h
119
+ else
120
+ node["audit"]["attributes"].to_h
121
+ end
122
+ end
123
+
116
124
  def inspec_opts
117
- inputs = node["audit"]["attributes"].to_h
125
+ inputs = inputs_from_attributes
126
+
118
127
  if node["audit"]["chef_node_attribute_enabled"]
119
128
  inputs["chef_node"] = node.to_h
120
129
  inputs["chef_node"]["chef_environment"] = node.chef_environment
@@ -300,6 +309,11 @@ class Chef
300
309
  raise "CMPL002: Unrecognized Compliance Phase fetcher (node['audit']['fetcher'] = #{fetcher}). Supported fetchers are: #{SUPPORTED_FETCHERS.join(", ")}, or nil. For more information, see the documentation at https://docs.chef.io/chef_compliance_phase#fetch-profiles"
301
310
  end
302
311
  end
312
+
313
+ if !node["audit"]["attributes"].empty? && !node["audit"]["inputs"].empty?
314
+ raise "CMPL011: both node['audit']['inputs'] and node['audit']['attributes'] are set. The node['audit']['attributes'] setting is deprecated and should not be used."
315
+ end
316
+
303
317
  @validation_passed = true
304
318
  end
305
319
  end
@@ -49,15 +49,15 @@ class Chef
49
49
  #
50
50
  # value = secret(name: "test1", service: :aws_secrets_manager, version: "v1", config: { region: "us-west-1" })
51
51
  # log "My secret is #{value}"
52
- def secret(name: nil, version: nil, service: nil, config: nil)
53
- Chef::Log.warn <<~EOM.gsub("\n", "")
52
+ def secret(name: nil, version: nil, service: nil, config: {})
53
+ Chef::Log.warn <<~EOM.gsub("\n", " ")
54
54
  The secrets Chef Infra language helper is currently in beta.
55
55
  This helper will most likely change over time in potentially breaking ways.
56
56
  If you have feedback or you'd like to be part of the future design of this
57
57
  helper e-mail us at secrets_management_beta@progress.com"
58
58
  EOM
59
59
  sensitive(true) if is_a?(Chef::Resource)
60
- Chef::SecretFetcher.for_service(service, config).fetch(name, version)
60
+ Chef::SecretFetcher.for_service(service, config, run_context).fetch(name, version)
61
61
  end
62
62
  end
63
63
  end
@@ -308,8 +308,6 @@ class Chef
308
308
  super("No secret service provided. Supported services are: :#{fetcher_service_names.join(" :")}")
309
309
  end
310
310
  end
311
-
312
- class MissingVaultName < RuntimeError; end
313
311
  end
314
312
 
315
313
  # Exception class for collecting multiple failures. Used when running
@@ -27,7 +27,7 @@ class Chef
27
27
  # Failed to register this client with the server.
28
28
  def self.registration_failed(node_name, exception, config)
29
29
  error_inspector = ErrorInspectors::RegistrationErrorInspector.new(node_name, exception, config)
30
- headline = "Chef encountered an error attempting to create the client \"#{node_name}\""
30
+ headline = "Chef Infra Client encountered an error attempting to create the client \"#{node_name}\""
31
31
  description = ErrorDescription.new(headline)
32
32
  error_inspector.add_explanation(description)
33
33
  description
@@ -35,7 +35,7 @@ class Chef
35
35
 
36
36
  def self.node_load_failed(node_name, exception, config)
37
37
  error_inspector = ErrorInspectors::NodeLoadErrorInspector.new(node_name, exception, config)
38
- headline = "Chef encountered an error attempting to load the node data for \"#{node_name}\""
38
+ headline = "Chef Infra Client encountered an error attempting to load the node data for \"#{node_name}\""
39
39
  description = ErrorDescription.new(headline)
40
40
  error_inspector.add_explanation(description)
41
41
  description
@@ -41,7 +41,7 @@ class Chef
41
41
  end
42
42
  end
43
43
 
44
- action :run do
44
+ action :run, description: "Run a command." do
45
45
  if creates && sentinel_file.exist?
46
46
  logger.debug("#{new_resource} sentinel file #{sentinel_file} exists - nothing to do")
47
47
  return false
@@ -158,7 +158,7 @@ class Chef
158
158
  if new_resource.group_name && (current_resource.group_name != new_resource.group_name)
159
159
  dscl_create_group
160
160
  end
161
- if new_resource.gid && (current_resource.gid != new_resource.gid)
161
+ if new_resource.gid && (current_resource.gid != new_resource.gid.to_s)
162
162
  set_gid
163
163
  end
164
164
  if new_resource.members || new_resource.excluded_members
@@ -43,22 +43,22 @@ class Chef
43
43
  types[type]
44
44
  end
45
45
 
46
- action :create do
46
+ action :create, description: "Create a launchd property list." do
47
47
  manage_plist(:create)
48
48
  end
49
49
 
50
- action :create_if_missing do
50
+ action :create_if_missing, description: "Create a launchd property list, if it does not already exist." do
51
51
  manage_plist(:create_if_missing)
52
52
  end
53
53
 
54
- action :delete do
54
+ action :delete, description: "Delete a launchd property list. This will unload a daemon or agent, if loaded." do
55
55
  if ::File.exists?(path)
56
56
  manage_service(:disable)
57
57
  end
58
58
  manage_plist(:delete)
59
59
  end
60
60
 
61
- action :enable do
61
+ action :enable, description: "Create a launchd property list, and then ensure that it is enabled. If a launchd property list already exists, but does not match, updates the property list to match, and then restarts the daemon or agent." do
62
62
  manage_service(:nothing)
63
63
  manage_plist(:create) do
64
64
  notifies :restart, "macosx_service[#{label}]", :immediately
@@ -66,13 +66,13 @@ class Chef
66
66
  manage_service(:enable)
67
67
  end
68
68
 
69
- action :disable do
69
+ action :disable, description: "Disable a launchd property list." do
70
70
  return unless ::File.exist?(path)
71
71
 
72
72
  manage_service(:disable)
73
73
  end
74
74
 
75
- action :restart do
75
+ action :restart, description: "Restart a launchd managed daemon or agent." do
76
76
  manage_service(:restart)
77
77
  end
78
78
 
@@ -55,7 +55,7 @@ class Chef
55
55
  end
56
56
  end
57
57
 
58
- action :checkout do
58
+ action :checkout, description: "Clone or check out the source. When a checkout is available, this provider does nothing." do
59
59
  if target_dir_non_existent_or_empty?
60
60
  converge_by("perform checkout of #{new_resource.repository} into #{new_resource.destination}") do
61
61
  shell_out!(checkout_command, run_options)
@@ -65,7 +65,7 @@ class Chef
65
65
  end
66
66
  end
67
67
 
68
- action :export do
68
+ action :export, description: "Export the source, excluding or removing any version control artifacts." do
69
69
  if target_dir_non_existent_or_empty?
70
70
  action_force_export
71
71
  else
@@ -73,13 +73,13 @@ class Chef
73
73
  end
74
74
  end
75
75
 
76
- action :force_export do
76
+ action :force_export, description: "Export the source, excluding or removing any version control artifacts and force an export of the source that is overwriting the existing copy (if it exists)." do
77
77
  converge_by("export #{new_resource.repository} into #{new_resource.destination}") do
78
78
  shell_out!(export_command, run_options)
79
79
  end
80
80
  end
81
81
 
82
- action :sync do
82
+ action :sync, description: "Update the source to the specified version, or get a new clone or checkout. This action causes a hard reset of the index and working tree, discarding any uncommitted changes." do
83
83
  assert_target_directory_valid!
84
84
  if ::File.exist?(::File.join(new_resource.destination, ".svn"))
85
85
  current_rev = find_current_revision
@@ -1,4 +1,4 @@
1
- # This file was generated by Chef
1
+ # This file was generated by Chef Infra
2
2
  # Do NOT modify this file by hand.
3
3
 
4
4
  [<%= @config.repositoryid %>]
@@ -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")
@@ -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