chef 18.4.2 → 18.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (223) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -1
  3. data/chef.gemspec +7 -7
  4. data/lib/chef/application/client.rb +12 -0
  5. data/lib/chef/client.rb +10 -16
  6. data/lib/chef/compliance/runner.rb +10 -0
  7. data/lib/chef/cookbook/chefignore.rb +4 -1
  8. data/lib/chef/cookbook/cookbook_version_loader.rb +1 -1
  9. data/lib/chef/cookbook/synchronizer.rb +7 -1
  10. data/lib/chef/cookbook_manifest.rb +2 -2
  11. data/lib/chef/file_access_control/unix.rb +9 -9
  12. data/lib/chef/file_cache.rb +17 -2
  13. data/lib/chef/file_content_management/deploy/target_io.rb +29 -0
  14. data/lib/chef/file_content_management/deploy.rb +4 -1
  15. data/lib/chef/formatters/doc.rb +1 -1
  16. data/lib/chef/mixin/file_class.rb +3 -1
  17. data/lib/chef/mixin/get_source_from_package.rb +1 -1
  18. data/lib/chef/mixin/openssl_helper.rb +1 -1
  19. data/lib/chef/node/attribute.rb +3 -11
  20. data/lib/chef/node/immutable_collections.rb +15 -8
  21. data/lib/chef/node/mixin/state_tracking.rb +6 -3
  22. data/lib/chef/node.rb +1 -1
  23. data/lib/chef/policy_builder/policyfile.rb +8 -0
  24. data/lib/chef/provider/.gitkeep +0 -0
  25. data/lib/chef/provider/cookbook_file.rb +1 -1
  26. data/lib/chef/provider/cron.rb +1 -1
  27. data/lib/chef/provider/directory.rb +15 -15
  28. data/lib/chef/provider/file.rb +42 -29
  29. data/lib/chef/provider/git.rb +8 -8
  30. data/lib/chef/provider/group/aix.rb +1 -1
  31. data/lib/chef/provider/group/dscl.rb +1 -1
  32. data/lib/chef/provider/group/gpasswd.rb +2 -2
  33. data/lib/chef/provider/group/groupadd.rb +1 -1
  34. data/lib/chef/provider/group/groupmod.rb +2 -2
  35. data/lib/chef/provider/group/pw.rb +2 -2
  36. data/lib/chef/provider/group/solaris.rb +2 -2
  37. data/lib/chef/provider/group/usermod.rb +2 -2
  38. data/lib/chef/provider/group.rb +1 -1
  39. data/lib/chef/provider/http_request.rb +2 -3
  40. data/lib/chef/provider/ifconfig/aix.rb +1 -1
  41. data/lib/chef/provider/ifconfig/debian.rb +3 -3
  42. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  43. data/lib/chef/provider/ifconfig.rb +1 -1
  44. data/lib/chef/provider/link.rb +10 -10
  45. data/lib/chef/provider/mount/aix.rb +4 -4
  46. data/lib/chef/provider/mount/linux.rb +4 -4
  47. data/lib/chef/provider/mount/mount.rb +11 -11
  48. data/lib/chef/provider/package/apt.rb +2 -11
  49. data/lib/chef/provider/package/bff.rb +3 -3
  50. data/lib/chef/provider/package/chocolatey.rb +54 -24
  51. data/lib/chef/provider/package/dpkg.rb +3 -3
  52. data/lib/chef/provider/package/freebsd/base.rb +1 -1
  53. data/lib/chef/provider/package/habitat.rb +5 -3
  54. data/lib/chef/provider/package/ips.rb +2 -2
  55. data/lib/chef/provider/package/openbsd.rb +3 -2
  56. data/lib/chef/provider/package/pacman.rb +4 -4
  57. data/lib/chef/provider/package/paludis.rb +2 -2
  58. data/lib/chef/provider/package/portage.rb +1 -1
  59. data/lib/chef/provider/package/powershell.rb +1 -0
  60. data/lib/chef/provider/package/rpm.rb +2 -2
  61. data/lib/chef/provider/package/smartos.rb +2 -2
  62. data/lib/chef/provider/package/snap.rb +2 -1
  63. data/lib/chef/provider/package/snap_tm.rb +79 -0
  64. data/lib/chef/provider/package/solaris.rb +4 -4
  65. data/lib/chef/provider/package/zypper.rb +4 -5
  66. data/lib/chef/provider/package.rb +1 -1
  67. data/lib/chef/provider/remote_directory.rb +5 -5
  68. data/lib/chef/provider/remote_file/http.rb +2 -3
  69. data/lib/chef/provider/remote_file.rb +1 -1
  70. data/lib/chef/provider/route.rb +9 -9
  71. data/lib/chef/provider/service/aix.rb +1 -1
  72. data/lib/chef/provider/service/aixinit.rb +4 -4
  73. data/lib/chef/provider/service/arch.rb +6 -6
  74. data/lib/chef/provider/service/debian.rb +5 -5
  75. data/lib/chef/provider/service/freebsd.rb +7 -7
  76. data/lib/chef/provider/service/gentoo.rb +5 -5
  77. data/lib/chef/provider/service/init.rb +2 -2
  78. data/lib/chef/provider/service/insserv.rb +2 -2
  79. data/lib/chef/provider/service/invokercd.rb +1 -1
  80. data/lib/chef/provider/service/openbsd.rb +7 -7
  81. data/lib/chef/provider/service/redhat.rb +3 -3
  82. data/lib/chef/provider/service/solaris.rb +2 -2
  83. data/lib/chef/provider/service/systemd.rb +2 -2
  84. data/lib/chef/provider/service/upstart.rb +2 -2
  85. data/lib/chef/provider/service/windows.rb +0 -1
  86. data/lib/chef/provider/subversion.rb +8 -8
  87. data/lib/chef/provider/systemd_unit.rb +3 -3
  88. data/lib/chef/provider/template.rb +1 -1
  89. data/lib/chef/provider/user/aix.rb +3 -3
  90. data/lib/chef/provider/user/linux.rb +7 -2
  91. data/lib/chef/provider/user/pw.rb +3 -3
  92. data/lib/chef/provider/user/solaris.rb +7 -7
  93. data/lib/chef/provider/user.rb +7 -8
  94. data/lib/chef/provider/yum_repository.rb +1 -3
  95. data/lib/chef/provider/zypper_repository.rb +1 -1
  96. data/lib/chef/providers.rb +1 -0
  97. data/lib/chef/resource/.gitkeep +0 -0
  98. data/lib/chef/resource/alternatives.rb +2 -2
  99. data/lib/chef/resource/apt_preference.rb +1 -1
  100. data/lib/chef/resource/apt_repository.rb +7 -9
  101. data/lib/chef/resource/apt_update.rb +3 -3
  102. data/lib/chef/resource/bff_package.rb +1 -1
  103. data/lib/chef/resource/chef_client_config.rb +3 -2
  104. data/lib/chef/resource/chef_client_systemd_timer.rb +5 -0
  105. data/lib/chef/resource/chef_gem.rb +1 -1
  106. data/lib/chef/resource/chef_sleep.rb +1 -1
  107. data/lib/chef/resource/cookbook_file.rb +1 -1
  108. data/lib/chef/resource/cron/cron.rb +1 -1
  109. data/lib/chef/resource/cron/cron_d.rb +1 -1
  110. data/lib/chef/resource/cron_access.rb +1 -1
  111. data/lib/chef/resource/directory.rb +1 -1
  112. data/lib/chef/resource/dpkg_package.rb +1 -1
  113. data/lib/chef/resource/execute.rb +8 -6
  114. data/lib/chef/resource/file/verification/json.rb +1 -1
  115. data/lib/chef/resource/file/verification/systemd_unit.rb +1 -1
  116. data/lib/chef/resource/file/verification/yaml.rb +1 -1
  117. data/lib/chef/resource/file.rb +1 -1
  118. data/lib/chef/resource/freebsd_package.rb +2 -2
  119. data/lib/chef/resource/group.rb +1 -1
  120. data/lib/chef/resource/habitat/habitat_package.rb +1 -1
  121. data/lib/chef/resource/habitat/habitat_sup.rb +9 -9
  122. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +2 -2
  123. data/lib/chef/resource/habitat_install.rb +5 -4
  124. data/lib/chef/resource/hostname.rb +11 -10
  125. data/lib/chef/resource/http_request.rb +1 -1
  126. data/lib/chef/resource/ifconfig.rb +1 -1
  127. data/lib/chef/resource/inspec_input.rb +3 -1
  128. data/lib/chef/resource/inspec_waiver.rb +1 -1
  129. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  130. data/lib/chef/resource/ips_package.rb +2 -2
  131. data/lib/chef/resource/kernel_module.rb +2 -2
  132. data/lib/chef/resource/link.rb +1 -1
  133. data/lib/chef/resource/locale.rb +2 -2
  134. data/lib/chef/resource/mount.rb +1 -1
  135. data/lib/chef/resource/notify_group.rb +1 -1
  136. data/lib/chef/resource/ohai.rb +1 -1
  137. data/lib/chef/resource/ohai_hint.rb +1 -1
  138. data/lib/chef/resource/openbsd_package.rb +2 -2
  139. data/lib/chef/resource/package.rb +1 -1
  140. data/lib/chef/resource/pacman_package.rb +1 -1
  141. data/lib/chef/resource/paludis_package.rb +1 -1
  142. data/lib/chef/resource/portage_package.rb +1 -1
  143. data/lib/chef/resource/powershell_package.rb +4 -0
  144. data/lib/chef/resource/reboot.rb +1 -1
  145. data/lib/chef/resource/remote_directory.rb +1 -1
  146. data/lib/chef/resource/remote_file.rb +1 -1
  147. data/lib/chef/resource/rhsm_errata.rb +1 -1
  148. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  149. data/lib/chef/resource/rhsm_register.rb +1 -1
  150. data/lib/chef/resource/rhsm_repo.rb +3 -4
  151. data/lib/chef/resource/rhsm_subscription.rb +8 -9
  152. data/lib/chef/resource/route.rb +1 -1
  153. data/lib/chef/resource/rpm_package.rb +1 -1
  154. data/lib/chef/resource/scm/git.rb +1 -1
  155. data/lib/chef/resource/scm/subversion.rb +1 -1
  156. data/lib/chef/resource/selinux/common_helpers.rb +1 -1
  157. data/lib/chef/resource/selinux_boolean.rb +1 -1
  158. data/lib/chef/resource/selinux_fcontext.rb +3 -3
  159. data/lib/chef/resource/selinux_install.rb +1 -1
  160. data/lib/chef/resource/selinux_login.rb +1 -1
  161. data/lib/chef/resource/selinux_module.rb +5 -5
  162. data/lib/chef/resource/selinux_permissive.rb +2 -2
  163. data/lib/chef/resource/selinux_port.rb +2 -2
  164. data/lib/chef/resource/selinux_state.rb +2 -2
  165. data/lib/chef/resource/selinux_user.rb +1 -1
  166. data/lib/chef/resource/smartos_package.rb +2 -2
  167. data/lib/chef/resource/snap_package.rb +24 -1
  168. data/lib/chef/resource/solaris_package.rb +1 -1
  169. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  170. data/lib/chef/resource/sudo.rb +5 -5
  171. data/lib/chef/resource/support/client.erb +1 -1
  172. data/lib/chef/resource/swap_file.rb +6 -6
  173. data/lib/chef/resource/sysctl.rb +6 -5
  174. data/lib/chef/resource/systemd_unit.rb +1 -1
  175. data/lib/chef/resource/template.rb +1 -1
  176. data/lib/chef/resource/timezone.rb +5 -5
  177. data/lib/chef/resource/user/aix_user.rb +2 -2
  178. data/lib/chef/resource/user/linux_user.rb +2 -2
  179. data/lib/chef/resource/user/pw_user.rb +2 -2
  180. data/lib/chef/resource/user/solaris_user.rb +2 -2
  181. data/lib/chef/resource/user_ulimit.rb +1 -1
  182. data/lib/chef/resource/yum_repository.rb +1 -1
  183. data/lib/chef/resource/zypper_package.rb +2 -2
  184. data/lib/chef/resource/zypper_repository.rb +2 -2
  185. data/lib/chef/run_lock.rb +3 -0
  186. data/lib/chef/scan_access_control.rb +6 -6
  187. data/lib/chef/target_io/dir.rb +12 -0
  188. data/lib/chef/target_io/etc.rb +16 -0
  189. data/lib/chef/target_io/file.rb +12 -0
  190. data/lib/chef/target_io/fileutils.rb +12 -0
  191. data/lib/chef/target_io/http.rb +22 -0
  192. data/lib/chef/target_io/io.rb +12 -0
  193. data/lib/chef/target_io/shadow.rb +44 -0
  194. data/lib/chef/target_io/train/dir.rb +69 -0
  195. data/lib/chef/target_io/train/etc.rb +112 -0
  196. data/lib/chef/target_io/train/file.rb +219 -0
  197. data/lib/chef/target_io/train/fileutils.rb +220 -0
  198. data/lib/chef/target_io/train/http.rb +117 -0
  199. data/lib/chef/target_io/train/io.rb +13 -0
  200. data/lib/chef/target_io/train/shadow.rb +52 -0
  201. data/lib/chef/target_io/train_compat.rb +7 -0
  202. data/lib/chef/target_io.rb +9 -0
  203. data/lib/chef/util/backup.rb +1 -1
  204. data/lib/chef/util/diff.rb +14 -1
  205. data/lib/chef/util/file_edit.rb +4 -4
  206. data/lib/chef/version.rb +1 -1
  207. data/lib/chef.rb +2 -0
  208. data/spec/functional/resource/remote_file_spec.rb +1 -1
  209. data/spec/integration/client/fips_spec.rb +11 -2
  210. data/spec/integration/client/open_ssl_spec.rb +20 -0
  211. data/spec/spec_helper.rb +3 -1
  212. data/spec/support/platform_helpers.rb +20 -7
  213. data/spec/unit/client_spec.rb +0 -16
  214. data/spec/unit/file_cache_spec.rb +64 -0
  215. data/spec/unit/mixin/openssl_helper_spec.rb +6 -1
  216. data/spec/unit/provider/apt_repository_spec.rb +1 -1
  217. data/spec/unit/provider/package/chocolatey_spec.rb +17 -12
  218. data/spec/unit/provider/package/windows_spec.rb +5 -5
  219. data/spec/unit/provider/package/zypper_spec.rb +0 -10
  220. data/spec/unit/provider/route_spec.rb +6 -4
  221. data/spec/unit/resource/rhsm_repo_spec.rb +1 -0
  222. data/spec/unit/resource/rhsm_subscription_spec.rb +2 -0
  223. metadata +31 -10
@@ -20,8 +20,8 @@ require_relative "habitat_sup"
20
20
  class Chef
21
21
  class Resource
22
22
  class HabitatSupSystemd < HabitatSup
23
- provides :habitat_sup, os: "linux"
24
- provides :habitat_sup_systemd
23
+ provides :habitat_sup, os: "linux", target_mode: true
24
+ provides :habitat_sup_systemd, target_mode: true
25
25
 
26
26
  action :run do
27
27
  super()
@@ -19,7 +19,7 @@ require_relative "../resource"
19
19
  class Chef
20
20
  class Resource
21
21
  class HabitatInstall < Chef::Resource
22
- provides :habitat_install
22
+ provides :habitat_install, target_mode: true
23
23
 
24
24
  description "Use the **habitat_install** resource to install Chef Habitat."
25
25
  introduced "17.3"
@@ -70,7 +70,7 @@ class Chef
70
70
  description: "Specify the version of `Habitat` you would like to install."
71
71
 
72
72
  action :install, description: "Installs Habitat. Does nothing if the `hab` binary is found in the default location for the system (`/bin/hab` on Linux, `/usr/local/bin/hab` on macOS, `C:/habitat/hab.exe` on Windows)" do
73
- if ::File.exist?(hab_path)
73
+ if ::TargetIO::File.exist?(hab_path)
74
74
  cmd = shell_out!([hab_path, "--version"].flatten.compact.join(" "))
75
75
  version = %r{hab (\d*\.\d*\.\d[^\/]*)}.match(cmd.stdout)[1]
76
76
  return if version == new_resource.hab_version
@@ -94,7 +94,7 @@ class Chef
94
94
  path habfile
95
95
  destination "#{Chef::Config[:file_cache_path]}/habitat"
96
96
  action :extract
97
- not_if { ::Dir.exist?("c:\\habitat") }
97
+ not_if { ::TargetIO::Dir.exist?("c:\\habitat") }
98
98
  end
99
99
 
100
100
  directory "c:\\habitat" do
@@ -127,6 +127,7 @@ class Chef
127
127
  remote_file ::File.join(Chef::Config[:file_cache_path], "hab-install.sh") do
128
128
  source new_resource.install_url
129
129
  sensitive true
130
+ mode 0755
130
131
  end
131
132
 
132
133
  execute "installing with hab-install.sh" do
@@ -235,7 +236,7 @@ class Chef
235
236
  end
236
237
 
237
238
  def hab_command
238
- cmd = "bash #{Chef::Config[:file_cache_path]}/hab-install.sh"
239
+ cmd = "#{Chef::Config[:file_cache_path]}/hab-install.sh"
239
240
  cmd << " -v #{new_resource.hab_version} " if new_resource.hab_version
240
241
  cmd << " -t x86_64-linux-kernel2" if node["kernel"]["release"].to_i < 3
241
242
  cmd
@@ -24,7 +24,7 @@ class Chef
24
24
  # @since 14.0.0
25
25
  class Hostname < Chef::Resource
26
26
 
27
- provides :hostname
27
+ provides :hostname, target_mode: true
28
28
 
29
29
  description "Use the **hostname** resource to set the system's hostname, configure hostname and hosts config file, and re-run the Ohai hostname plugin so the hostname will be available in subsequent cookbooks."
30
30
  introduced "14.0"
@@ -99,7 +99,7 @@ class Chef
99
99
 
100
100
  action_class do
101
101
  def append_replacing_matching_lines(path, regex, string)
102
- text = IO.read(path).split("\n")
102
+ text = TargetIO::IO.read(path).split("\n")
103
103
  text.reject! { |s| s =~ regex }
104
104
  text += [ string ]
105
105
  file path do
@@ -107,7 +107,7 @@ class Chef
107
107
  owner "root"
108
108
  group node["root_group"]
109
109
  mode "0644"
110
- not_if { IO.read(path).split("\n").include?(string) }
110
+ not_if { TargetIO::IO.read(path).split("\n").include?(string) }
111
111
  end
112
112
  end
113
113
 
@@ -181,14 +181,14 @@ class Chef
181
181
  end
182
182
  when linux?
183
183
  case
184
- when ::File.exist?("/usr/bin/hostnamectl") && !docker?
184
+ when ::TargetIO::File.exist?("/usr/bin/hostnamectl") && !docker?
185
185
  # use hostnamectl whenever we find it on linux (as systemd takes over the world)
186
186
  # this must come before other methods like /etc/hostname and /etc/sysconfig/network
187
187
  execute "hostnamectl set-hostname #{new_resource.hostname}" do
188
188
  notifies :reload, "ohai[reload hostname]"
189
189
  not_if { shell_out!("hostnamectl status", returns: [0, 1]).stdout =~ /Static hostname:\s*#{new_resource.hostname}\s*$/ }
190
190
  end
191
- when ::File.exist?("/etc/hostname")
191
+ when ::TargetIO::File.exist?("/etc/hostname")
192
192
  # debian family uses /etc/hostname
193
193
  # arch also uses /etc/hostname
194
194
  # the "platform: iox_xr, platform_family: wrlinux, os: linux" platform also hits this
@@ -201,10 +201,10 @@ class Chef
201
201
  group node["root_group"]
202
202
  mode "0644"
203
203
  end
204
- when ::File.file?("/etc/sysconfig/network")
204
+ when ::TargetIO::File.file?("/etc/sysconfig/network")
205
205
  # older non-systemd RHEL/Fedora derived
206
206
  append_replacing_matching_lines("/etc/sysconfig/network", /^HOSTNAME\s*=/, "HOSTNAME=#{new_resource.hostname}")
207
- when ::File.exist?("/etc/HOSTNAME")
207
+ when ::TargetIO::File.exist?("/etc/HOSTNAME")
208
208
  # SuSE/openSUSE uses /etc/HOSTNAME
209
209
  file "/etc/HOSTNAME" do
210
210
  content "#{new_resource.hostname}\n"
@@ -212,7 +212,7 @@ class Chef
212
212
  group node["root_group"]
213
213
  mode "0644"
214
214
  end
215
- when ::File.exist?("/etc/conf.d/hostname")
215
+ when ::TargetIO::File.exist?("/etc/conf.d/hostname")
216
216
  # Gentoo
217
217
  file "/etc/conf.d/hostname" do
218
218
  content "hostname=\"#{new_resource.hostname}\"\n"
@@ -226,7 +226,7 @@ class Chef
226
226
  # that manage sysctls on linux.
227
227
  append_replacing_matching_lines("/etc/sysctl.conf", /^\s+kernel\.hostname\s+=/, "kernel.hostname=#{new_resource.hostname}")
228
228
  end
229
- when ::File.exist?("/etc/rc.conf")
229
+ when ::TargetIO::File.exist?("/etc/rc.conf")
230
230
  # *BSD systems with /etc/rc.conf + /etc/myname
231
231
  append_replacing_matching_lines("/etc/rc.conf", /^\s+hostname\s+=/, "hostname=#{new_resource.hostname}")
232
232
 
@@ -236,7 +236,7 @@ class Chef
236
236
  group node["root_group"]
237
237
  mode "0644"
238
238
  end
239
- when ::File.exist?("/usr/sbin/svccfg") # solaris 5.11
239
+ when ::TargetIO::File.exist?("/usr/sbin/svccfg") # solaris 5.11
240
240
  execute "svccfg -s system/identity:node setprop config/nodename=\'#{new_resource.hostname}\'" do
241
241
  notifies :run, "execute[svcadm refresh]", :immediately
242
242
  notifies :run, "execute[svcadm restart]", :immediately
@@ -259,6 +259,7 @@ class Chef
259
259
  WINDOWS_EC2_CONFIG = 'C:\Program Files\Amazon\Ec2ConfigService\Settings\config.xml'.freeze
260
260
 
261
261
  raise "Windows hostnames cannot contain a period." if new_resource.hostname.include?(".")
262
+ raise "Windows not supported in Target Mode" if ChefConfig::Config.target_mode?
262
263
 
263
264
  # suppress EC2 config service from setting our hostname
264
265
  if ::File.exist?(WINDOWS_EC2_CONFIG)
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class HttpRequest < Chef::Resource
25
25
 
26
- provides :http_request
26
+ provides :http_request, target_mode: true
27
27
 
28
28
  description "Use the **http_request** resource to send an HTTP request (`GET`, `PUT`, `POST`, `DELETE`, `HEAD`, or `OPTIONS`) with an arbitrary message. This resource is often useful when custom callbacks are necessary."
29
29
 
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class Ifconfig < Chef::Resource
25
25
 
26
- provides :ifconfig
26
+ provides :ifconfig, target_mode: true
27
27
 
28
28
  description "Use the **ifconfig** resource to manage interfaces on Unix and Linux systems. Note: This resource requires the ifconfig binary to be present on the system and may require additional packages to be installed first. On Ubuntu 18.04 or later you will need to install the `ifupdown` package, which disables the built in Netplan functionality. Warning: This resource will not work with Fedora release 33 or later."
29
29
  examples <<~DOC
@@ -19,7 +19,7 @@ require_relative "../resource"
19
19
  class Chef
20
20
  class Resource
21
21
  class InspecInput < Chef::Resource
22
- provides :inspec_input
22
+ provides :inspec_input, target_mode: true
23
23
 
24
24
  description "Use the **inspec_input** resource to add an input to the Compliance Phase."
25
25
  introduced "17.5"
@@ -105,6 +105,8 @@ class Chef
105
105
  def build_source
106
106
  return new_resource.source unless new_resource.source.nil?
107
107
  return nil unless new_resource.input.count(::File::SEPARATOR) > 0 || (::File::ALT_SEPARATOR && new_resource.input.count(::File::ALT_SEPARATOR) > 0 )
108
+
109
+ # InSpec gets processed locally, so no TargetIO
108
110
  return nil unless ::File.exist?(new_resource.input)
109
111
 
110
112
  new_resource.input
@@ -19,7 +19,7 @@ require_relative "../resource"
19
19
  class Chef
20
20
  class Resource
21
21
  class InspecWaiver < Chef::Resource
22
- provides :inspec_waiver
22
+ provides :inspec_waiver, target_mode: true
23
23
 
24
24
  description "Use the **inspec_waiver** resource to add a waiver to the Compliance Phase."
25
25
  introduced "17.5"
@@ -23,7 +23,7 @@ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
23
23
  class Chef
24
24
  class Resource
25
25
  class InspecWaiverFileEntry < Chef::Resource
26
- provides :inspec_waiver_file_entry
26
+ provides :inspec_waiver_file_entry, target_mode: true
27
27
 
28
28
  description "Use the **inspec_waiver_file_entry** resource to add or remove entries from an InSpec waiver file. This can be used in conjunction with the Compliance Phase."
29
29
  introduced "17.1"
@@ -23,8 +23,8 @@ class Chef
23
23
  class Resource
24
24
  class IpsPackage < ::Chef::Resource::Package
25
25
 
26
- provides :ips_package
27
- provides :package, os: "solaris2"
26
+ provides :ips_package, target_mode: true
27
+ provides :package, os: "solaris2", target_mode: true
28
28
 
29
29
  description "Use the **ips_package** resource to manage packages (using Image Packaging System (IPS)) on the Solaris 11 platform."
30
30
 
@@ -12,7 +12,7 @@ class Chef
12
12
  class Resource
13
13
  class KernelModule < Chef::Resource
14
14
 
15
- provides :kernel_module
15
+ provides :kernel_module, target_mode: true
16
16
 
17
17
  description "Use the **kernel_module** resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, enable, install, and uninstall modules."
18
18
  introduced "14.3"
@@ -232,7 +232,7 @@ class Chef
232
232
  # see if the module is listed in /proc/modules or not
233
233
  # @return [Boolean]
234
234
  def module_loaded?
235
- /^#{new_resource.modname}/.match?(::File.read("/proc/modules"))
235
+ /^#{new_resource.modname}/.match?(::TargetIO::File.read("/proc/modules"))
236
236
  end
237
237
  end
238
238
  end
@@ -25,7 +25,7 @@ class Chef
25
25
  class Link < Chef::Resource
26
26
  include Chef::Mixin::Securable
27
27
 
28
- provides :link
28
+ provides :link, target_mode: true
29
29
 
30
30
  description "Use the **link** resource to create symbolic or hard links.\n\n"\
31
31
  "A symbolic link—sometimes referred to as a soft link—is a directory entry"\
@@ -21,7 +21,7 @@ require "chef-utils/dist" unless defined?(ChefUtils::Dist)
21
21
  class Chef
22
22
  class Resource
23
23
  class Locale < Chef::Resource
24
- provides :locale
24
+ provides :locale, target_mode: true
25
25
 
26
26
  description "Use the **locale** resource to set the system's locale on Debian and Windows systems. Windows support was added in Chef Infra Client 16.0"
27
27
  introduced "14.5"
@@ -79,7 +79,7 @@ class Chef
79
79
  lang get_system_locale_windows
80
80
  else
81
81
  begin
82
- old_content = ::File.read(LOCALE_CONF)
82
+ old_content = ::TargetIO::File.read(LOCALE_CONF)
83
83
  locale_values = Hash[old_content.split("\n").map { |v| v.split("=") }]
84
84
  lang locale_values["LANG"]
85
85
  rescue Errno::ENOENT => e
@@ -24,7 +24,7 @@ class Chef
24
24
  class Mount < Chef::Resource
25
25
  description "Use the **mount** resource to manage a mounted file system."
26
26
 
27
- provides :mount
27
+ provides :mount, target_mode: true
28
28
 
29
29
  default_action :mount
30
30
  allowed_actions :mount, :umount, :unmount, :remount, :enable, :disable
@@ -19,7 +19,7 @@ require_relative "../resource"
19
19
  class Chef
20
20
  class Resource
21
21
  class NotifyGroup < Chef::Resource
22
- provides :notify_group
22
+ provides :notify_group, target_mode: true
23
23
 
24
24
  description "The notify_group resource does nothing, and always fires notifications which are set on it. Use it to DRY blocks of notifications that are common to multiple resources, and provide a single target for other resources to notify. Unlike most resources, its default action is :nothing."
25
25
  introduced "15.8"
@@ -26,7 +26,7 @@ class Chef
26
26
  class Resource
27
27
  class Ohai < Chef::Resource
28
28
 
29
- provides :ohai
29
+ provides :ohai, target_mode: true
30
30
 
31
31
  description "Use the **ohai** resource to reload the Ohai configuration on a node. This allows recipes that change system attributes (like a recipe that adds a user) to refer to those attributes later on during the #{ChefUtils::Dist::Infra::PRODUCT} run."
32
32
 
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class OhaiHint < Chef::Resource
23
23
 
24
- provides(:ohai_hint) { true }
24
+ provides(:ohai_hint, target_mode: true) { true }
25
25
 
26
26
  description "Use the **ohai_hint** resource to aid in configuration detection by passing hint data to Ohai."
27
27
  introduced "14.0"
@@ -25,8 +25,8 @@ require_relative "../provider/package/openbsd"
25
25
  class Chef
26
26
  class Resource
27
27
  class OpenbsdPackage < Chef::Resource::Package
28
- provides :openbsd_package
29
- provides :package, os: "openbsd"
28
+ provides :openbsd_package, target_mode: true
29
+ provides :package, os: "openbsd", target_mode: true
30
30
 
31
31
  description "Use the **openbsd_package** resource to manage packages for the OpenBSD platform."
32
32
  introduced "12.1"
@@ -22,7 +22,7 @@ require_relative "../resource"
22
22
  class Chef
23
23
  class Resource
24
24
  class Package < Chef::Resource
25
- provides :package
25
+ provides :package, target_mode: true
26
26
 
27
27
  description "Use the **package** resource to manage packages. When the package is"\
28
28
  " installed from a local file (such as with RubyGems, dpkg, or RPM"\
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class PacmanPackage < Chef::Resource::Package
24
24
 
25
- provides :pacman_package
25
+ provides :pacman_package, target_mode: true
26
26
 
27
27
  allowed_actions :install, :upgrade, :remove, :purge
28
28
 
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class PaludisPackage < Chef::Resource::Package
25
25
 
26
- provides :paludis_package
26
+ provides :paludis_package, target_mode: true
27
27
 
28
28
  description "Use the **paludis_package** resource to manage packages for the Paludis platform."
29
29
  introduced "12.1"
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class PortagePackage < Chef::Resource::Package
24
24
 
25
- provides :portage_package
25
+ provides :portage_package, target_mode: true
26
26
 
27
27
  description "Use the **portage_package** resource to manage packages for the Gentoo platform."
28
28
 
@@ -44,6 +44,10 @@ class Chef
44
44
  description: "Skip validating module author.",
45
45
  default: false, introduced: "14.3", desired_state: false
46
46
 
47
+ property :allow_clobber, [TrueClass, FalseClass],
48
+ description: "Overrides warning messages about installation conflicts about existing commands on a computer.",
49
+ default: false, introduced: "18.5"
50
+
47
51
  end
48
52
  end
49
53
  end
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class Reboot < Chef::Resource
25
25
 
26
- provides :reboot
26
+ provides :reboot, target_mode: true
27
27
 
28
28
  description "Use the **reboot** resource to reboot a node, a necessary step with some"\
29
29
  " installations on certain platforms. This resource is supported for use on"\
@@ -26,7 +26,7 @@ class Chef
26
26
  class RemoteDirectory < Chef::Resource::Directory
27
27
  include Chef::Mixin::Securable
28
28
 
29
- provides :remote_directory
29
+ provides :remote_directory, target_mode: true
30
30
 
31
31
  description "Use the **remote_directory** resource to incrementally transfer a directory from a cookbook to a node. The directory that is copied from the cookbook should be located under `COOKBOOK_NAME/files/default/REMOTE_DIRECTORY`. The `remote_directory` resource will obey file specificity."
32
32
 
@@ -29,7 +29,7 @@ class Chef
29
29
  class RemoteFile < Chef::Resource::File
30
30
  include Chef::Mixin::Securable
31
31
 
32
- provides :remote_file
32
+ provides :remote_file, target_mode: true
33
33
 
34
34
  description "Use the **remote_file** resource to transfer a file from a remote location using file specificity. This resource is similar to the **file** resource. Note: Fetching files from the `files/` directory in a cookbook should be done with the **cookbook_file** resource."
35
35
 
@@ -20,7 +20,7 @@ require_relative "../resource"
20
20
  class Chef
21
21
  class Resource
22
22
  class RhsmErrata < Chef::Resource
23
- provides(:rhsm_errata) { true }
23
+ provides(:rhsm_errata, target_mode: true) { true }
24
24
 
25
25
  description "Use the **rhsm_errata** resource to install packages associated with a given Red Hat Subscription Manager Errata ID. This is helpful if packages to mitigate a single vulnerability must be installed on your hosts."
26
26
  introduced "14.0"
@@ -20,7 +20,7 @@ require_relative "../resource"
20
20
  class Chef
21
21
  class Resource
22
22
  class RhsmErrataLevel < Chef::Resource
23
- provides(:rhsm_errata_level) { true }
23
+ provides(:rhsm_errata_level, target_mode: true) { true }
24
24
 
25
25
  description "Use the **rhsm_errata_level** resource to install all packages of a specified errata level from the Red Hat Subscription Manager. For example, you can ensure that all packages associated with errata marked at a 'Critical' security level are installed."
26
26
  introduced "14.0"
@@ -22,7 +22,7 @@ require "shellwords" unless defined?(Shellwords)
22
22
  class Chef
23
23
  class Resource
24
24
  class RhsmRegister < Chef::Resource
25
- provides(:rhsm_register) { true }
25
+ provides(:rhsm_register, target_mode: true) { true }
26
26
 
27
27
  description "Use the **rhsm_register** resource to register a node with the Red Hat Subscription Manager or a local Red Hat Satellite server."
28
28
  introduced "14.0"
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class RhsmRepo < Chef::Resource
23
23
 
24
- provides(:rhsm_repo) { true }
24
+ provides(:rhsm_repo, target_mode: true) { true }
25
25
 
26
26
  description "Use the **rhsm_repo** resource to enable or disable Red Hat Subscription Manager repositories that are made available via attached subscriptions."
27
27
  introduced "14.0"
@@ -65,9 +65,8 @@ class Chef
65
65
 
66
66
  action_class do
67
67
  def repo_enabled?(repo)
68
- # FIXME: use shell_out()
69
- cmd = Mixlib::ShellOut.new("subscription-manager repos --list-enabled", env: { LANG: "en_US" })
70
- cmd.run_command
68
+ # FIXME: Add `env` support
69
+ cmd = shell_out("subscription-manager repos --list-enabled", env: { LANG: "en_US" })
71
70
  repo == "*" || !cmd.stdout.match(/Repo ID:\s+#{repo}$/).nil?
72
71
  end
73
72
  end
@@ -21,7 +21,7 @@ class Chef
21
21
  class Resource
22
22
  class RhsmSubscription < Chef::Resource
23
23
 
24
- provides(:rhsm_subscription) { true }
24
+ provides(:rhsm_subscription, target_mode: true) { true }
25
25
 
26
26
  description "Use the **rhsm_subscription** resource to add or remove Red Hat Subscription Manager subscriptions from your host. This can be used when a host's activation_key does not attach all necessary subscriptions to your host."
27
27
  introduced "14.0"
@@ -50,10 +50,9 @@ class Chef
50
50
 
51
51
  action_class do
52
52
  def subscription_attached?(subscription)
53
- # FIXME: use shell_out
54
- cmd = Mixlib::ShellOut.new("subscription-manager list --consumed | grep #{subscription}", env: { LANG: "en_US" })
55
- cmd.run_command
56
- !cmd.stdout.match(/Pool ID:\s+#{subscription}$/).nil?
53
+ cmd = "subscription-manager list --consumed | grep #{subscription}"
54
+ stdout = shell_out(cmd, env: { LANG: "en_US" }).stdout
55
+ !stdout.match(/Pool ID:\s+#{subscription}$/).nil?
57
56
  end
58
57
 
59
58
  def serials_by_pool
@@ -61,10 +60,10 @@ class Chef
61
60
  pool = nil
62
61
  serial = nil
63
62
 
64
- # FIXME: use shell_out
65
- cmd = Mixlib::ShellOut.new("subscription-manager list --consumed", env: { LANG: "en_US" })
66
- cmd.run_command
67
- cmd.stdout.lines.each do |line|
63
+ cmd = "subscription-manager list --consumed"
64
+ stdout = shell_out(cmd, env: { LANG: "en_US" }).stdout
65
+
66
+ stdout.lines.each do |line|
68
67
  line.strip!
69
68
  key, value = line.split(/:\s+/, 2)
70
69
  next unless ["Pool ID", "Serial"].include?(key)
@@ -23,7 +23,7 @@ class Chef
23
23
  class Resource
24
24
  class Route < Chef::Resource
25
25
 
26
- provides :route
26
+ provides :route, target_mode: true
27
27
 
28
28
  default_action :add
29
29
  allowed_actions :add, :delete
@@ -22,7 +22,7 @@ class Chef
22
22
  class Resource
23
23
  class RpmPackage < Chef::Resource::Package
24
24
 
25
- provides :rpm_package
25
+ provides :rpm_package, target_mode: true
26
26
 
27
27
  allowed_actions :install, :upgrade, :remove
28
28
 
@@ -23,7 +23,7 @@ class Chef
23
23
  class Git < Chef::Resource
24
24
  use "scm"
25
25
 
26
- provides :git
26
+ provides :git, target_mode: true
27
27
 
28
28
  description "Use the **git** resource to manage source control resources that exist in a git repository. git version 1.6.5 (or higher) is required to use all of the functionality in the git resource."
29
29
  examples <<~DOC
@@ -24,7 +24,7 @@ class Chef
24
24
  class Subversion < Chef::Resource
25
25
  use "scm"
26
26
 
27
- provides :subversion
27
+ provides :subversion, target_mode: true
28
28
 
29
29
  description "Use the **subversion** resource to manage source control resources that exist in a Subversion repository. Warning: The subversion resource has known bugs and may not work as expected. For more information see Chef GitHub issues, particularly [#4050](https://github.com/chef/chef/issues/4050) and [#4257](https://github.com/chef/chef/issues/4257)."
30
30
  examples <<~DOC
@@ -40,7 +40,7 @@ class Chef
40
40
  def selinux_activate_required?
41
41
  return false unless platform_family?("debian")
42
42
 
43
- !File.read("/etc/default/grub").match?("security=selinux")
43
+ !TargetIO::File.read("/etc/default/grub").match?("security=selinux")
44
44
  end
45
45
  end
46
46
  end
@@ -20,7 +20,7 @@ class Chef
20
20
  class SelinuxBoolean < Chef::Resource
21
21
  unified_mode true
22
22
 
23
- provides :selinux_boolean
23
+ provides :selinux_boolean, target_mode: true
24
24
 
25
25
  description "Use **selinux_boolean** resource to set SELinux boolean values."
26
26
  introduced "18.0"
@@ -20,7 +20,7 @@ class Chef
20
20
  class SelinuxFcontext < Chef::Resource
21
21
  unified_mode true
22
22
 
23
- provides :selinux_fcontext
23
+ provides :selinux_fcontext, target_mode: true
24
24
 
25
25
  description "Use the **selinux_fcontext** resource to set the SELinux context of files using the `semanage fcontext` command."
26
26
  introduced "18.0"
@@ -95,7 +95,7 @@ class Chef
95
95
  # if path is not absolute, ignore it and search everything
96
96
  common = "/" if common[0] != "/"
97
97
 
98
- if ::File.exist? common
98
+ if ::TargetIO::File.exist? common
99
99
  shell_out!("find #{common.shellescape} -ignore_readdir_race -regextype posix-egrep -regex #{spec.shellescape} -prune -print0 | xargs -0 restorecon -iRv")
100
100
  end
101
101
  end
@@ -157,4 +157,4 @@ class Chef
157
157
  end
158
158
  end
159
159
  end
160
- end
160
+ end
@@ -18,7 +18,7 @@ class Chef
18
18
  class SelinuxInstall < Chef::Resource
19
19
  unified_mode true
20
20
 
21
- provides :selinux_install
21
+ provides :selinux_install, target_mode: true
22
22
 
23
23
  description "Use **selinux_install** resource to encapsulates the set of selinux packages to install in order to manage selinux. It also ensures the directory `/etc/selinux` is created."
24
24
  introduced "18.0"
@@ -19,7 +19,7 @@ class Chef
19
19
  class SelinuxLogin < Chef::Resource
20
20
  unified_mode true
21
21
 
22
- provides :selinux_login
22
+ provides :selinux_login, target_mode: true
23
23
 
24
24
  description "Use the **selinux_login** resource to add, update, or remove SELinux user to OS login mappings."
25
25
  introduced "18.1"
@@ -18,7 +18,7 @@ class Chef
18
18
  class SelinuxModule < Chef::Resource
19
19
  unified_mode true
20
20
 
21
- provides :selinux_module
21
+ provides :selinux_module, target_mode: true
22
22
 
23
23
  description "Use **selinux_module** module resource to create an SELinux policy module from a cookbook file or content provided as a string."
24
24
  introduced "18.0"
@@ -103,7 +103,7 @@ class Chef
103
103
  notifies :run, "execute[Install SELinux module '#{selinux_module_filepath("pp")}']", :immediately
104
104
  end
105
105
 
106
- raise "Compilation must have failed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::File.exist?(selinux_module_filepath("pp"))
106
+ raise "Compilation must have failed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::TargetIO::File.exist?(selinux_module_filepath("pp"))
107
107
 
108
108
  execute "Install SELinux module '#{selinux_module_filepath("pp")}'" do
109
109
  command "semodule --install '#{selinux_module_filepath("pp")}'"
@@ -113,7 +113,7 @@ class Chef
113
113
 
114
114
  action :delete, description: "Remove module source files from `/etc/selinux/local`." do
115
115
  %w{fc if pp te}.each do |type|
116
- next unless ::File.exist?(selinux_module_filepath(type))
116
+ next unless ::TargetIO::File.exist?(selinux_module_filepath(type))
117
117
 
118
118
  file selinux_module_filepath(type) do
119
119
  action :delete
@@ -122,7 +122,7 @@ class Chef
122
122
  end
123
123
 
124
124
  action :install, description: "Install a compiled module into the system." do
125
- raise "Module must be compiled before it can be installed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::File.exist?(selinux_module_filepath("pp"))
125
+ raise "Module must be compiled before it can be installed, no 'pp' file found at: '#{selinux_module_filepath("pp")}'" unless ::TargetIO::File.exist?(selinux_module_filepath("pp"))
126
126
 
127
127
  unless list_installed_modules.include? new_resource.module_name
128
128
  converge_by "Install SELinux module #{selinux_module_filepath("pp")}" do
@@ -140,4 +140,4 @@ class Chef
140
140
  end
141
141
  end
142
142
  end
143
- end
143
+ end