chef 16.0.257 → 16.0.275

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +30 -16
  3. data/chef.gemspec +1 -1
  4. data/lib/chef/knife/environment_compare.rb +1 -1
  5. data/lib/chef/knife/list.rb +1 -1
  6. data/lib/chef/knife/supermarket_install.rb +1 -1
  7. data/lib/chef/knife/yaml_convert.rb +2 -2
  8. data/lib/chef/provider/execute.rb +1 -1
  9. data/lib/chef/provider/package/freebsd/base.rb +2 -1
  10. data/lib/chef/provider/package/homebrew.rb +1 -1
  11. data/lib/chef/provider/package/macports.rb +0 -2
  12. data/lib/chef/provider/package/windows.rb +26 -51
  13. data/lib/chef/provider/user/dscl.rb +1 -1
  14. data/lib/chef/resource/alternatives.rb +65 -4
  15. data/lib/chef/resource/apt_package.rb +31 -2
  16. data/lib/chef/resource/apt_preference.rb +34 -5
  17. data/lib/chef/resource/apt_repository.rb +22 -15
  18. data/lib/chef/resource/apt_update.rb +6 -4
  19. data/lib/chef/resource/archive_file.rb +5 -4
  20. data/lib/chef/resource/bash.rb +1 -1
  21. data/lib/chef/resource/batch.rb +1 -1
  22. data/lib/chef/resource/bff_package.rb +1 -1
  23. data/lib/chef/resource/breakpoint.rb +1 -1
  24. data/lib/chef/resource/build_essential.rb +8 -4
  25. data/lib/chef/resource/cab_package.rb +1 -1
  26. data/lib/chef/resource/chef_client_cron.rb +12 -9
  27. data/lib/chef/resource/chef_client_scheduled_task.rb +9 -6
  28. data/lib/chef/resource/chef_client_systemd_timer.rb +10 -7
  29. data/lib/chef/resource/chef_gem.rb +6 -2
  30. data/lib/chef/resource/chef_handler.rb +1 -1
  31. data/lib/chef/resource/chef_sleep.rb +7 -4
  32. data/lib/chef/resource/chef_vault_secret.rb +3 -3
  33. data/lib/chef/resource/chocolatey_config.rb +5 -3
  34. data/lib/chef/resource/chocolatey_feature.rb +5 -3
  35. data/lib/chef/resource/chocolatey_package.rb +5 -3
  36. data/lib/chef/resource/chocolatey_source.rb +5 -3
  37. data/lib/chef/resource/cookbook_file.rb +3 -2
  38. data/lib/chef/resource/cron.rb +15 -15
  39. data/lib/chef/resource/cron_access.rb +7 -4
  40. data/lib/chef/resource/cron_d.rb +37 -23
  41. data/lib/chef/resource/csh.rb +1 -1
  42. data/lib/chef/resource/directory.rb +1 -1
  43. data/lib/chef/resource/dmg_package.rb +18 -15
  44. data/lib/chef/resource/dnf_package.rb +1 -1
  45. data/lib/chef/resource/dpkg_package.rb +1 -1
  46. data/lib/chef/resource/execute.rb +2 -2
  47. data/lib/chef/resource/file.rb +5 -4
  48. data/lib/chef/resource/freebsd_package.rb +1 -1
  49. data/lib/chef/resource/gem_package.rb +6 -6
  50. data/lib/chef/resource/group.rb +1 -1
  51. data/lib/chef/resource/homebrew_cask.rb +1 -1
  52. data/lib/chef/resource/homebrew_package.rb +1 -1
  53. data/lib/chef/resource/homebrew_tap.rb +1 -1
  54. data/lib/chef/resource/hostname.rb +4 -4
  55. data/lib/chef/resource/http_request.rb +1 -1
  56. data/lib/chef/resource/ifconfig.rb +7 -7
  57. data/lib/chef/resource/ips_package.rb +1 -1
  58. data/lib/chef/resource/kernel_module.rb +1 -1
  59. data/lib/chef/resource/ksh.rb +1 -1
  60. data/lib/chef/resource/launchd.rb +1 -1
  61. data/lib/chef/resource/link.rb +4 -4
  62. data/lib/chef/resource/locale.rb +1 -1
  63. data/lib/chef/resource/log.rb +1 -1
  64. data/lib/chef/resource/macos_userdefaults.rb +1 -1
  65. data/lib/chef/resource/macosx_service.rb +1 -1
  66. data/lib/chef/resource/macports_package.rb +1 -1
  67. data/lib/chef/resource/mdadm.rb +1 -1
  68. data/lib/chef/resource/mount.rb +1 -1
  69. data/lib/chef/resource/msu_package.rb +1 -1
  70. data/lib/chef/resource/ohai.rb +1 -1
  71. data/lib/chef/resource/ohai_hint.rb +1 -1
  72. data/lib/chef/resource/openbsd_package.rb +1 -1
  73. data/lib/chef/resource/openssl_dhparam.rb +1 -1
  74. data/lib/chef/resource/openssl_ec_private_key.rb +1 -1
  75. data/lib/chef/resource/openssl_ec_public_key.rb +1 -1
  76. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -1
  77. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -1
  78. data/lib/chef/resource/openssl_x509_certificate.rb +1 -1
  79. data/lib/chef/resource/openssl_x509_crl.rb +1 -1
  80. data/lib/chef/resource/openssl_x509_request.rb +1 -1
  81. data/lib/chef/resource/osx_profile.rb +1 -1
  82. data/lib/chef/resource/package.rb +1 -1
  83. data/lib/chef/resource/pacman_package.rb +1 -1
  84. data/lib/chef/resource/paludis_package.rb +1 -1
  85. data/lib/chef/resource/perl.rb +1 -1
  86. data/lib/chef/resource/plist.rb +1 -1
  87. data/lib/chef/resource/portage_package.rb +1 -1
  88. data/lib/chef/resource/powershell_package.rb +1 -1
  89. data/lib/chef/resource/powershell_package_source.rb +1 -1
  90. data/lib/chef/resource/powershell_script.rb +1 -1
  91. data/lib/chef/resource/python.rb +1 -1
  92. data/lib/chef/resource/reboot.rb +1 -1
  93. data/lib/chef/resource/registry_key.rb +1 -1
  94. data/lib/chef/resource/remote_directory.rb +1 -1
  95. data/lib/chef/resource/remote_file.rb +1 -2
  96. data/lib/chef/resource/rhsm_errata.rb +1 -3
  97. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  98. data/lib/chef/resource/rhsm_register.rb +1 -2
  99. data/lib/chef/resource/rhsm_repo.rb +1 -2
  100. data/lib/chef/resource/rhsm_subscription.rb +1 -3
  101. data/lib/chef/resource/route.rb +1 -1
  102. data/lib/chef/resource/rpm_package.rb +5 -2
  103. data/lib/chef/resource/ruby.rb +1 -1
  104. data/lib/chef/resource/ruby_block.rb +1 -4
  105. data/lib/chef/resource/scm/_scm.rb +4 -3
  106. data/lib/chef/resource/scm/git.rb +1 -1
  107. data/lib/chef/resource/scm/subversion.rb +2 -2
  108. data/lib/chef/resource/script.rb +1 -1
  109. data/lib/chef/resource/service.rb +1 -1
  110. data/lib/chef/resource/smartos_package.rb +1 -1
  111. data/lib/chef/resource/snap_package.rb +1 -1
  112. data/lib/chef/resource/solaris_package.rb +1 -1
  113. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  114. data/lib/chef/resource/sudo.rb +4 -4
  115. data/lib/chef/resource/swap_file.rb +2 -2
  116. data/lib/chef/resource/sysctl.rb +61 -2
  117. data/lib/chef/resource/systemd_unit.rb +2 -2
  118. data/lib/chef/resource/timezone.rb +1 -1
  119. data/lib/chef/resource/user.rb +2 -2
  120. data/lib/chef/resource/user_ulimit.rb +24 -22
  121. data/lib/chef/resource/windows_ad_join.rb +1 -1
  122. data/lib/chef/resource/windows_auto_run.rb +2 -2
  123. data/lib/chef/resource/windows_certificate.rb +1 -1
  124. data/lib/chef/resource/windows_dfs_folder.rb +1 -1
  125. data/lib/chef/resource/windows_dfs_namespace.rb +1 -1
  126. data/lib/chef/resource/windows_dfs_server.rb +1 -1
  127. data/lib/chef/resource/windows_env.rb +10 -1
  128. data/lib/chef/resource/windows_feature.rb +57 -2
  129. data/lib/chef/resource/windows_feature_dism.rb +15 -2
  130. data/lib/chef/resource/windows_feature_powershell.rb +29 -2
  131. data/lib/chef/resource/windows_firewall_rule.rb +9 -5
  132. data/lib/chef/resource/windows_font.rb +10 -1
  133. data/lib/chef/resource/windows_package.rb +63 -3
  134. data/lib/chef/resource/windows_pagefile.rb +30 -2
  135. data/lib/chef/resource/windows_path.rb +18 -1
  136. data/lib/chef/resource/windows_printer.rb +25 -5
  137. data/lib/chef/resource/windows_printer_port.rb +29 -1
  138. data/lib/chef/resource/windows_security_policy.rb +1 -1
  139. data/lib/chef/resource/windows_service.rb +1 -1
  140. data/lib/chef/resource/windows_share.rb +21 -1
  141. data/lib/chef/resource/windows_shortcut.rb +13 -2
  142. data/lib/chef/resource/windows_task.rb +122 -8
  143. data/lib/chef/resource/windows_uac.rb +20 -1
  144. data/lib/chef/resource/windows_workgroup.rb +19 -3
  145. data/lib/chef/resource/yum_package.rb +88 -6
  146. data/lib/chef/resource/yum_repository.rb +28 -11
  147. data/lib/chef/resource/zypper_package.rb +29 -3
  148. data/lib/chef/resource/zypper_repository.rb +17 -5
  149. data/lib/chef/resource_inspector.rb +1 -1
  150. data/lib/chef/scan_access_control.rb +1 -1
  151. data/lib/chef/version.rb +1 -1
  152. data/spec/functional/resource/link_spec.rb +3 -3
  153. data/spec/functional/resource/remote_file_spec.rb +1 -1
  154. data/spec/integration/knife/raw_spec.rb +4 -4
  155. data/spec/integration/knife/redirection_spec.rb +2 -2
  156. data/spec/support/platform_helpers.rb +0 -13
  157. data/spec/support/shared/functional/http.rb +2 -2
  158. data/spec/support/shared/unit/mock_shellout.rb +1 -1
  159. data/spec/unit/file_access_control_spec.rb +1 -1
  160. data/spec/unit/mixin/shell_out_spec.rb +25 -31
  161. data/spec/unit/provider/apt_repository_spec.rb +27 -27
  162. data/spec/unit/provider/zypper_repository_spec.rb +17 -17
  163. data/spec/unit/provider_resolver_spec.rb +2 -2
  164. metadata +10 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1825ecbde1edecfa8a8bfbebe425f053bf176e06553f2c74bbf7d98a2d213967
4
- data.tar.gz: 2f661249cfa4551fe980d52810b4e14bb12c776486dce1687a7ccc378e55e8d5
3
+ metadata.gz: d68311a7ab5b1738bbd739ab5b89069da39f8fc8c639e1d261ac1d5836261bf8
4
+ data.tar.gz: b5b5cac5dac1febf24cf947c70a868165d9c5dde49fad8a76128055e59b81f85
5
5
  SHA512:
6
- metadata.gz: 34558ba429fea801f67e4296253e7f42cced441fe6304c7529ab8489740494f10f58ef21993508618fa3f67098f3bab2d552ef1dde984b32dbda1f652264e488
7
- data.tar.gz: 33acd0f1f9d3707862505e4273f18525657487e9185586d54196c5d3cff9916f5ec37540c2737eabc439a9128ec99ebc759ce21470ed1c6874b4d0741d17f99b
6
+ metadata.gz: 758923d89c1f5eadcaf35cfd262f303b6c19309c1ae5a4faa2a7c7d5d2646f0501e76ca00de6a64f02b1ac76fb1b8527e901ab71607bcbc8996992877b51f5de
7
+ data.tar.gz: 200a93d8b87be3c3e46f764cd24b48414f46e118eb286b092beb7d3bd405905f1573437dd7c9597efb5e6d571876e2776a0f92f958dc966c8bb2c34c517fa130
data/Rakefile CHANGED
@@ -17,6 +17,9 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
+ # we need this to resolve files required by lib/chef/dist
21
+ $LOAD_PATH.unshift(File.expand_path("../chef-config/lib", __FILE__))
22
+
20
23
  begin
21
24
  require_relative "tasks/rspec"
22
25
  require_relative "tasks/dependencies"
@@ -27,26 +30,36 @@ rescue LoadError => e
27
30
  puts "Skipping missing rake dep: #{e}"
28
31
  end
29
32
 
33
+ require "bundler/gem_helper"
34
+
30
35
  ENV["CHEF_LICENSE"] = "accept-no-persist"
31
36
 
32
- # hack the chef-config install to run before the traditional install task
33
- task :super_install do
34
- %w{chef-utils chef-config}.each do |gem|
35
- path = ::File.join(::File.dirname(__FILE__), gem)
36
- Dir.chdir(path)
37
- sh("rake install")
37
+ namespace :pre_install do
38
+ desc "Runs 'rake install' for the gems that live in subdirectories in this repo"
39
+ task :install_gems_from_dirs do
40
+ %w{chef-utils chef-config}.each do |gem|
41
+ path = ::File.join(::File.dirname(__FILE__), gem)
42
+ Dir.chdir(path) do
43
+ sh("rake install")
44
+ end
45
+ end
38
46
  end
39
47
 
40
- # Templating the powershell extensions so we can inject distro constants
41
- template_file = ::File.join(::File.dirname(__FILE__), "distro", "templates", "powershell", "chef", "chef.psm1.erb")
42
- psm1_path = ::File.join(::File.dirname(__FILE__), "distro", "powershell", "chef")
43
- FileUtils.mkdir_p psm1_path
44
- template = ERB.new(IO.read(template_file))
45
- chef_psm1 = template.result
46
- File.open(::File.join(psm1_path, "chef.psm1"), "w") { |f| f.write(chef_psm1) }
48
+ desc "Renders the powershell extensions with distro flavoring"
49
+ task :render_powershell_extension do
50
+ template_file = ::File.join(::File.dirname(__FILE__), "distro", "templates", "powershell", "chef", "chef.psm1.erb")
51
+ psm1_path = ::File.join(::File.dirname(__FILE__), "distro", "powershell", "chef")
52
+ FileUtils.mkdir_p psm1_path
53
+ template = ERB.new(IO.read(template_file))
54
+ chef_psm1 = template.result
55
+ File.open(::File.join(psm1_path, "chef.psm1"), "w") { |f| f.write(chef_psm1) }
56
+ end
57
+
58
+ task all: ["pre_install:install_gems_from_dirs", "pre_install:render_powershell_extension"]
47
59
  end
48
60
 
49
- task install: :super_install
61
+ # hack in all the preinstall tasks to occur before the tradtional install task
62
+ task install: "pre_install:all"
50
63
 
51
64
  # make sure we build the correct gemspec on windows
52
65
  gemspec = Gem.win_platform? ? "chef-universal-mingw32" : "chef"
@@ -55,8 +68,9 @@ Bundler::GemHelper.install_tasks name: gemspec
55
68
  # this gets appended to the normal bundler install helper
56
69
  task :install do
57
70
  chef_bin_path = ::File.join(::File.dirname(__FILE__), "chef-bin")
58
- Dir.chdir(chef_bin_path)
59
- sh("rake install:force")
71
+ Dir.chdir(chef_bin_path) do
72
+ sh("rake install:force")
73
+ end
60
74
  end
61
75
 
62
76
  task :pedant, :chef_zero_spec
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
34
34
  s.add_dependency "net-ssh-multi", "~> 1.2", ">= 1.2.1"
35
35
  s.add_dependency "net-sftp", "~> 2.1", ">= 2.1.2"
36
36
  s.add_dependency "ed25519", "~> 1.2" # ed25519 ssh key support
37
- s.add_dependency "bcrypt_pbkdf", "~> 1.0" # ed25519 ssh key support
37
+ s.add_dependency "bcrypt_pbkdf", "= 1.1.0.rc1" # ed25519 ssh key support
38
38
  s.add_dependency "highline", ">= 1.6.9", "< 3"
39
39
  s.add_dependency "tty-screen", "~> 0.6" # knife list
40
40
  s.add_dependency "pastel" # knife ui.color
@@ -81,7 +81,7 @@ class Chef
81
81
 
82
82
  def constraint_list(environments)
83
83
  constraints = {}
84
- environments.each do |env, url| # rubocop:disable Performance/HashEachMethods
84
+ environments.each do |env, url| # rubocop:disable Style/HashEachMethods
85
85
  # Because you cannot modify the default environment I filter it out here.
86
86
  unless env == "_default"
87
87
  envdata = Chef::Environment.load(env)
@@ -90,7 +90,7 @@ class Chef
90
90
 
91
91
  # Flatten out directory results if necessary
92
92
  if config[:flat]
93
- dir_results.each do |result, children| # rubocop:disable Performance/HashEachMethods
93
+ dir_results.each do |result, children| # rubocop:disable Style/HashEachMethods
94
94
  results += children
95
95
  end
96
96
  dir_results = []
@@ -96,7 +96,7 @@ class Chef
96
96
  extract_cookbook(upstream_file, downloader.version)
97
97
 
98
98
  # TODO: it'd be better to store these outside the cookbook repo and
99
- # keep them around, e.g., in ~/Library/Caches on OS X.
99
+ # keep them around, e.g., in ~/Library/Caches on macOS.
100
100
  ui.info("Removing downloaded tarball")
101
101
  File.unlink(upstream_file)
102
102
 
@@ -56,7 +56,7 @@ class Chef::Knife::YamlConvert < Chef::Knife
56
56
  end
57
57
 
58
58
  # Unfortunately, per the YAML spec, comments are stripped when we load, so we lose them on conversion
59
- yaml_hash = ::YAML.safe_load(yaml_contents)
59
+ yaml_hash = ::YAML.safe_load(yaml_contents, permitted_classes: [Symbol])
60
60
  unless yaml_hash.is_a?(Hash) && yaml_hash.key?("resources")
61
61
  ui.fatal!("YAML recipe '#{source_file}' must contain a top-level 'resources' hash (YAML sequence), i.e. 'resources:'")
62
62
  end
@@ -81,7 +81,7 @@ class Chef::Knife::YamlConvert < Chef::Knife
81
81
 
82
82
  ruby_contents << "#{type} \"#{name}\" do"
83
83
  r.each do |k, v|
84
- ruby_contents << " #{k} \"#{v}\""
84
+ ruby_contents << " #{k} #{v.inspect}"
85
85
  end
86
86
  ruby_contents << "end\n"
87
87
  end
@@ -49,7 +49,7 @@ class Chef
49
49
 
50
50
  converge_by("execute #{description}") do
51
51
  begin
52
- shell_out!(command, opts)
52
+ shell_out!(command, **opts)
53
53
  rescue Mixlib::ShellOut::ShellCommandFailed
54
54
  if sensitive?
55
55
  ex = Mixlib::ShellOut::ShellCommandFailed.new("Command execution failed. STDOUT/STDERR suppressed for sensitive resource")
@@ -58,7 +58,8 @@ class Chef
58
58
 
59
59
  def makefile_variable_value(variable, dir = nil)
60
60
  options = dir ? { cwd: dir } : {}
61
- make_v = shell_out!("make", "-V", variable, options.merge!(env: nil, returns: [0, 1]))
61
+ options.merge!(env: nil, returns: [0, 1])
62
+ make_v = shell_out!("make", "-V", variable, **options)
62
63
  make_v.exitstatus == 0 ? make_v.stdout.strip.split($OUTPUT_RECORD_SEPARATOR).first : nil # $\ is the line separator, i.e. newline.
63
64
  end
64
65
  end
@@ -27,7 +27,7 @@ class Chef
27
27
  allow_nils
28
28
  use_multipackage_api
29
29
 
30
- provides :package, os: "darwin", override: true
30
+ provides :package, os: "darwin"
31
31
  provides :homebrew_package
32
32
 
33
33
  include Chef::Mixin::HomebrewUser
@@ -2,8 +2,6 @@ class Chef
2
2
  class Provider
3
3
  class Package
4
4
  class Macports < Chef::Provider::Package
5
-
6
- provides :package, os: "darwin"
7
5
  provides :macports_package
8
6
 
9
7
  def load_current_resource
@@ -36,6 +36,13 @@ class Chef
36
36
  require "chef/provider/package/windows/registry_uninstall_entry.rb"
37
37
 
38
38
  def define_resource_requirements
39
+ if new_resource.checksum
40
+ requirements.assert(:install) do |a|
41
+ a.assertion { new_resource.checksum.downcase == checksum(source_location) }
42
+ a.failure_message Chef::Exceptions::Package, "Checksum on resource (#{short_cksum(new_resource.checksum)}) does not match checksum on content (#{short_cksum(source_location)})"
43
+ end
44
+ end
45
+
39
46
  requirements.assert(:install) do |a|
40
47
  a.assertion { new_resource.source || msi? }
41
48
  a.failure_message Chef::Exceptions::NoWindowsPackageSource, "Source for package #{new_resource.package_name} must be specified in the resource's source property for package to be installed because the package_name property is used to test for the package installation state for this package type."
@@ -50,27 +57,15 @@ class Chef
50
57
  end
51
58
  end
52
59
 
53
- # load_current_resource is run in Chef::Provider#run_action when not in whyrun_mode?
54
60
  def load_current_resource
55
- @current_resource = Chef::Resource::WindowsPackage.new(new_resource.name)
56
- if downloadable_file_missing?
57
- logger.trace("We do not know the version of #{new_resource.source} because the file is not downloaded")
58
- # FIXME: this label should not be used. It could be set to nil. Probably what should happen is that
59
- # if the file hasn't been downloaded then load_current_resource must download the file here, and then
60
- # the else clause to set current_resource.version can always be run. Relying on a side-effect here
61
- # produces at least less readable code, if not outright buggy... (and I'm assuming that this isn't
62
- # wholly just a bug -- since if we only need the package_name to determine if its installed then we
63
- # need this, so I'm assuming we need to download the file to pull out the name in order to check
64
- # the registry -- which it still feels like we get wrong in the sense we're forcing always downloading
65
- # and then always installing(?) which violates idempotency -- and I'm having to think way too hard
66
- # about this and would need to go surfing around the code to determine what actually happens, probably
67
- # in every different package_provider...)
68
- current_resource.version(:unknown.to_s)
69
- else
70
- current_resource.version(package_provider.installed_version)
71
- new_resource.version(package_provider.package_version) if package_provider.package_version
61
+ if uri_scheme?(new_resource.source) && action == :install
62
+ download_source_file
72
63
  end
73
64
 
65
+ @current_resource = Chef::Resource::WindowsPackage.new(new_resource.name)
66
+ current_resource.version(package_provider.installed_version)
67
+ new_resource.version(package_provider.package_version) if package_provider.package_version
68
+
74
69
  current_resource
75
70
  end
76
71
 
@@ -139,17 +134,6 @@ class Chef
139
134
  end
140
135
  end
141
136
 
142
- action :install do
143
- if uri_scheme?(new_resource.source)
144
- download_source_file
145
- load_current_resource
146
- else
147
- validate_content!
148
- end
149
-
150
- super
151
- end
152
-
153
137
  # Chef::Provider::Package action_install + action_remove call install_package + remove_package
154
138
  # Pass those calls to the correct sub-provider
155
139
  def install_package(name, version)
@@ -245,6 +229,7 @@ class Chef
245
229
  end
246
230
 
247
231
  def resource_for_provider
232
+ # XXX: this is crazy
248
233
  @resource_for_provider = Chef::Resource::WindowsPackage.new(new_resource.name).tap do |r|
249
234
  r.source(Chef::Util::PathHelper.validate_path(source_location)) unless source_location.nil?
250
235
  r.cookbook_name = new_resource.cookbook_name
@@ -257,23 +242,22 @@ class Chef
257
242
  end
258
243
 
259
244
  def download_source_file
260
- source_resource.run_action(:create)
261
- logger.trace("#{new_resource} fetched source file to #{source_resource.path}")
262
- end
263
-
264
- def source_resource
265
- @source_resource ||= Chef::Resource::RemoteFile.new(default_download_cache_path, run_context).tap do |r|
266
- r.source(new_resource.source)
267
- r.cookbook_name = new_resource.cookbook_name
268
- r.checksum(new_resource.checksum)
269
- r.backup(false)
245
+ # It seems correct that this is a build_resource rather than declare_resource/DSL use since updating should not trigger a notification
246
+ # unless the downloaded file is actually installed. The case where the remote_file downloads the package but the package is already
247
+ # installed on the target should not trigger a notification since the running state did not change.
248
+ build_resource(:remote_file, default_download_cache_path) do
249
+ source(new_resource.source)
250
+ cookbook_name = new_resource.cookbook_name
251
+ checksum(new_resource.checksum)
252
+ backup(false)
270
253
 
271
254
  if new_resource.remote_file_attributes
272
255
  new_resource.remote_file_attributes.each do |(k, v)|
273
- r.send(k.to_sym, v)
256
+ send(k.to_sym, v)
274
257
  end
275
258
  end
276
- end
259
+ end.run_action(:create)
260
+ logger.trace("#{new_resource} fetched source file to #{default_download_cache_path}")
277
261
  end
278
262
 
279
263
  def default_download_cache_path
@@ -287,22 +271,13 @@ class Chef
287
271
  if new_resource.source.nil?
288
272
  nil
289
273
  elsif uri_scheme?(new_resource.source)
290
- source_resource.path
274
+ default_download_cache_path
291
275
  else
292
276
  new_source = Chef::Util::PathHelper.cleanpath(new_resource.source)
293
277
  ::File.exist?(new_source) ? new_source : nil
294
278
  end
295
279
  end
296
280
 
297
- def validate_content!
298
- if new_resource.checksum
299
- source_checksum = checksum(source_location)
300
- if new_resource.checksum.downcase != source_checksum
301
- raise Chef::Exceptions::ChecksumMismatch.new(short_cksum(new_resource.checksum), short_cksum(source_checksum))
302
- end
303
- end
304
- end
305
-
306
281
  def msi?
307
282
  return true if new_resource.installer_type == :msi
308
283
 
@@ -28,7 +28,7 @@ class Chef
28
28
  class User
29
29
  #
30
30
  # The most tricky bit of this provider is the way it deals with user passwords.
31
- # Mac OS X has different password shadow calculations based on the version.
31
+ # macOS has different password shadow calculations based on the version.
32
32
  # < 10.7 => password shadow calculation format SALTED-SHA1
33
33
  # => stored in: /var/db/shadow/hash/#{guid}
34
34
  # => shadow binary length 68 bytes
@@ -28,11 +28,72 @@ class Chef
28
28
 
29
29
  description "The alternatives resource allows for configuration of command alternatives in Linux using the alternatives or update-alternatives packages."
30
30
  introduced "16.0"
31
+ examples <<~DOC
32
+ **Install an alternative**:
33
+
34
+ ```ruby
35
+ alternatives 'python install 2' do
36
+ link_name 'python'
37
+ path '/usr/bin/python2.7'
38
+ priority 100
39
+ action :install
40
+ end
41
+ ```
42
+
43
+ **Set an alternative**:
44
+
45
+ ```ruby
46
+ alternatives 'python set version 3' do
47
+ link_name 'python'
48
+ path '/usr/bin/python3'
49
+ action :set
50
+ end
51
+ ```
52
+
53
+ **Set the automatic alternative state**:
54
+
55
+ ```ruby
56
+ alternatives 'python auto' do
57
+ link_name 'python'
58
+ action :auto
59
+ end
60
+ ```
61
+
62
+ **Refresh an alternative**:
63
+
64
+ ```ruby
65
+ alternatives 'python refresh' do
66
+ link_name 'python'
67
+ action :refresh
68
+ end
69
+ ```
70
+
71
+ **Remove an alternative**:
72
+
73
+ ```ruby
74
+ alternatives 'python remove' do
75
+ link_name 'python'
76
+ path '/usr/bin/python3'
77
+ action :remove
78
+ end
79
+ ```
80
+ DOC
81
+
82
+ property :link_name, String,
83
+ name_property: true,
84
+ description: "The name of the link to create. This will be the command you type on the command line such as `ruby` or `gcc`."
85
+
86
+ property :link, String,
87
+ default: lazy { |n| "/usr/bin/#{n.link_name}" },
88
+ default_description: "/usr/bin/LINK_NAME",
89
+ description: "The path to the alternatives link."
90
+
91
+ property :path, String,
92
+ description: "The full path to the original application binary such as `/usr/bin/ruby27`."
31
93
 
32
- property :link_name, String, name_property: true
33
- property :link, String, default: lazy { |n| "/usr/bin/#{n.link_name}" }
34
- property :path, String
35
- property :priority, [String, Integer], coerce: proc { |n| n.to_i }
94
+ property :priority, [String, Integer],
95
+ coerce: proc { |n| n.to_i },
96
+ description: "The priority of the alternative."
36
97
 
37
98
  def define_resource_requirements
38
99
  requirements.assert(:install) do |a|
@@ -25,11 +25,40 @@ class Chef
25
25
 
26
26
  provides :apt_package, target_mode: true
27
27
  provides :package, platform_family: "debian", target_mode: true
28
+ examples <<~DOC
29
+ **Install a package using package manager**:
28
30
 
29
- description "Use the apt_package resource to manage packages on Debian and Ubuntu platforms."
31
+ ```ruby
32
+ apt_package 'name of package' do
33
+ action :install
34
+ end
35
+ ```
36
+
37
+ **Install a package without specifying the default action**:
38
+
39
+ ```ruby
40
+ apt_package 'name of package'
41
+ ```
42
+
43
+ **Install multiple packages at once**:
44
+
45
+ ```ruby
46
+ apt_package %(package1 package2 package3)
47
+ ```
48
+
49
+ **Install without using recommend packages as a dependency**
50
+
51
+ ```ruby
52
+ package 'apache2' do
53
+ options '--no-install-recommends'
54
+ end
55
+ ```
56
+ DOC
57
+
58
+ description "Use the **apt_package** resource to manage packages on Debian and Ubuntu platforms."
30
59
 
31
60
  property :default_release, String,
32
- description: "The default release. For example: stable.",
61
+ description: "The default release. For example: `stable`.",
33
62
  desired_state: false
34
63
 
35
64
  property :overwrite_config_files, [TrueClass, FalseClass],
@@ -20,14 +20,43 @@ require_relative "../resource"
20
20
 
21
21
  class Chef
22
22
  class Resource
23
- # @since 13.3
24
23
  class AptPreference < Chef::Resource
25
24
  unified_mode true
26
25
 
27
26
  provides(:apt_preference) { true }
28
27
 
29
- description "The apt_preference resource allows for the creation of APT preference files. Preference files are used to control which package versions and sources are prioritized during installation."
28
+ description "Use the **apt_preference** resource to create APT [preference files](https://wiki.debian.org/AptPreferences). Preference files are used to control which package versions and sources are prioritized during installation."
30
29
  introduced "13.3"
30
+ examples <<~DOC
31
+ **Pin libmysqlclient16 to a version 5.1.49-3**:
32
+
33
+ ```ruby
34
+ apt_preference 'libmysqlclient16' do
35
+ pin 'version 5.1.49-3'
36
+ pin_priority '700'
37
+ end
38
+ ```
39
+
40
+ Note: The `pin_priority` of `700` ensures that this version will be preferred over any other available versions.
41
+
42
+ **Unpin a libmysqlclient16**:
43
+
44
+ ```ruby
45
+ apt_preference 'libmysqlclient16' do
46
+ action :remove
47
+ end
48
+ ```
49
+
50
+ **Pin all packages to prefer the packages.dotdeb.org repository**:
51
+
52
+ ```ruby
53
+ apt_preference 'dotdeb' do
54
+ glob '*'
55
+ pin 'origin packages.dotdeb.org'
56
+ pin_priority '700'
57
+ end
58
+ ```
59
+ DOC
31
60
 
32
61
  property :package_name, String,
33
62
  name_property: true,
@@ -36,15 +65,15 @@ class Chef
36
65
  validation_message: "The provided package name is not valid. Package names can only contain alphanumeric characters as well as _, -, +, or *!"
37
66
 
38
67
  property :glob, String,
39
- description: "Pin by glob() expression or with regular expressions surrounded by /."
68
+ description: "Pin by a `glob()` expression or with a regular expression surrounded by `/`."
40
69
 
41
70
  property :pin, String,
42
71
  description: "The package version or repository to pin.",
43
- required: true
72
+ required: [:add]
44
73
 
45
74
  property :pin_priority, [String, Integer],
46
75
  description: "Sets the Pin-Priority for a package. See <https://wiki.debian.org/AptPreferences> for more details.",
47
- required: true
76
+ required: [:add]
48
77
 
49
78
  default_action :add
50
79
  allowed_actions :add, :remove