summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2020-02-20 13:39:28 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2020-02-21 14:13:15 -0800
commit9b3cd8affcd5e73641f1135e5fc17ae89b50eec9 (patch)
tree435bfff68ab178a504b8b11e11c0b5b2f60a6551
parent04979a3ba5ca32e3c97ae492eae84829994697a0 (diff)
downloadchef-9b3cd8affcd5e73641f1135e5fc17ae89b50eec9.tar.gz
Convert more resources to unified_mode
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/resource/dsc_resource.rb4
-rw-r--r--lib/chef/resource/homebrew_cask.rb4
-rw-r--r--lib/chef/resource/homebrew_package.rb6
-rw-r--r--lib/chef/resource/homebrew_tap.rb4
-rw-r--r--lib/chef/resource/hostname.rb2
-rw-r--r--lib/chef/resource/ips_package.rb4
-rw-r--r--lib/chef/resource/kernel_module.rb55
-rw-r--r--lib/chef/resource/locale.rb13
-rw-r--r--lib/chef/resource/macos_userdefaults.rb8
-rw-r--r--lib/chef/resource/macosx_service.rb2
-rw-r--r--lib/chef/resource/sudo.rb15
-rw-r--r--lib/chef/resource/timezone.rb4
-rw-r--r--lib/chef/resource/yum_package.rb4
-rw-r--r--lib/chef/resource/zypper_package.rb3
14 files changed, 76 insertions, 52 deletions
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index 9c17139544..796009d896 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Edwards (<adamed@chef.io>)
#
-# Copyright:: Copyright 2014-2019, Chef Software Inc.
+# Copyright:: Copyright 2014-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@ require_relative "../dist"
class Chef
class Resource
class DscResource < Chef::Resource
+ unified_mode true
+
resource_name :dsc_resource
provides :dsc_resource
diff --git a/lib/chef/resource/homebrew_cask.rb b/lib/chef/resource/homebrew_cask.rb
index 70e1d7c6bb..c8d6fa6bda 100644
--- a/lib/chef/resource/homebrew_cask.rb
+++ b/lib/chef/resource/homebrew_cask.rb
@@ -2,7 +2,7 @@
# Author:: Joshua Timberman (<jtimberman@chef.io>)
# Author:: Graeme Mathieson (<mathie@woss.name>)
#
-# Copyright:: 2011-2018, Chef Software, Inc.
+# Copyright:: 2011-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@ require_relative "../mixin/homebrew_user"
class Chef
class Resource
class HomebrewCask < Chef::Resource
+ unified_mode true
+
resource_name :homebrew_cask
provides(:homebrew_cask) { true }
diff --git a/lib/chef/resource/homebrew_package.rb b/lib/chef/resource/homebrew_package.rb
index 55c61478ec..a33bdc63d6 100644
--- a/lib/chef/resource/homebrew_package.rb
+++ b/lib/chef/resource/homebrew_package.rb
@@ -2,8 +2,8 @@
# Author:: Joshua Timberman (<joshua@chef.io>)
# Author:: Graeme Mathieson (<mathie@woss.name>)
#
-# Copyright 2011-2016, Chef Software Inc.
-# Copyright 2014-2016, Chef Software, Inc <legal@chef.io>
+# Copyright 2011-2020, Chef Software Inc.
+# Copyright 2014-2020, Chef Software Inc.<legal@chef.io>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@ require_relative "../dist"
class Chef
class Resource
class HomebrewPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :homebrew_package
provides :package, os: "darwin"
diff --git a/lib/chef/resource/homebrew_tap.rb b/lib/chef/resource/homebrew_tap.rb
index 23738d6e51..15374f5a15 100644
--- a/lib/chef/resource/homebrew_tap.rb
+++ b/lib/chef/resource/homebrew_tap.rb
@@ -2,7 +2,7 @@
# Author:: Joshua Timberman (<jtimberman@chef.io>)
# Author:: Graeme Mathieson (<mathie@woss.name>)
#
-# Copyright:: 2011-2018, Chef Software, Inc.
+# Copyright:: 2011-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@ require_relative "../mixin/homebrew_user"
class Chef
class Resource
class HomebrewTap < Chef::Resource
+ unified_mode true
+
resource_name :homebrew_tap
provides(:homebrew_tap) { true }
diff --git a/lib/chef/resource/hostname.rb b/lib/chef/resource/hostname.rb
index 59db9fb953..ef0218ebaa 100644
--- a/lib/chef/resource/hostname.rb
+++ b/lib/chef/resource/hostname.rb
@@ -19,6 +19,8 @@ class Chef
# Sets the hostname and updates /etc/hosts on *nix systems
# @since 14.0.0
class Hostname < Chef::Resource
+ unified_mode true
+
resource_name :hostname
provides :hostname
diff --git a/lib/chef/resource/ips_package.rb b/lib/chef/resource/ips_package.rb
index 66cee48aee..341e459c09 100644
--- a/lib/chef/resource/ips_package.rb
+++ b/lib/chef/resource/ips_package.rb
@@ -1,6 +1,6 @@
#
# Author:: Jason Williams (<williamsjj@digitar.com>)
-# Copyright:: Copyright 2011-2016, Chef Software Inc.
+# Copyright:: Copyright 2011-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,8 @@ require_relative "../provider/package/ips"
class Chef
class Resource
class IpsPackage < ::Chef::Resource::Package
+ unified_mode true
+
resource_name :ips_package
provides :package, os: "solaris2"
provides :ips_package
diff --git a/lib/chef/resource/kernel_module.rb b/lib/chef/resource/kernel_module.rb
index 2f9b7748f6..3dc9c0bd4f 100644
--- a/lib/chef/resource/kernel_module.rb
+++ b/lib/chef/resource/kernel_module.rb
@@ -4,13 +4,15 @@
# The MIT License (MIT)
#
# Copyright 2016-2018, Shopify Inc.
-# Copyright 2018, Chef Software, Inc.
+# Copyright 2018-2020, Chef Software Inc.
require_relative "../resource"
class Chef
class Resource
class KernelModule < Chef::Resource
+ unified_mode true
+
resource_name :kernel_module
description "Use the kernel_module resource to manage kernel modules on Linux systems. This resource can load, unload, blacklist, disable, install, and uninstall modules."
@@ -81,15 +83,22 @@ class Chef
action :install do
description "Load kernel module, and ensure it loads on reboot."
+ with_run_context :root do
+ find_resource(:execute, "update initramfs") do
+ command initramfs_command
+ action :nothing
+ end
+ end
+
# create options file before loading the module
unless new_resource.options.nil?
file "#{new_resource.unload_dir}/options_#{new_resource.modname}.conf" do
content "options #{new_resource.modname} #{new_resource.options.join(" ")}\n"
- end.run_action(:create)
+ end
end
# load the module first before installing
- new_resource.run_action(:load)
+ action_load
directory new_resource.load_dir do
recursive true
@@ -99,17 +108,16 @@ class Chef
content "#{new_resource.modname}\n"
notifies :run, "execute[update initramfs]", :delayed
end
+ end
+ action :uninstall do
+ description "Unload a kernel module and remove module config, so it doesn't load on reboot."
with_run_context :root do
find_resource(:execute, "update initramfs") do
command initramfs_command
action :nothing
end
end
- end
-
- action :uninstall do
- description "Unload a kernel module and remove module config, so it doesn't load on reboot."
file "#{new_resource.load_dir}/#{new_resource.modname}.conf" do
action :delete
@@ -125,24 +133,12 @@ class Chef
action :delete
end
- with_run_context :root do
- find_resource(:execute, "update initramfs") do
- command initramfs_command
- action :nothing
- end
- end
-
- new_resource.run_action(:unload)
+ action_unload
end
action :blacklist do
description "Blacklist a kernel module."
- file "#{new_resource.unload_dir}/blacklist_#{new_resource.modname}.conf" do
- content "blacklist #{new_resource.modname}"
- notifies :run, "execute[update initramfs]", :delayed
- end
-
with_run_context :root do
find_resource(:execute, "update initramfs") do
command initramfs_command
@@ -150,17 +146,17 @@ class Chef
end
end
- new_resource.run_action(:unload)
+ file "#{new_resource.unload_dir}/blacklist_#{new_resource.modname}.conf" do
+ content "blacklist #{new_resource.modname}"
+ notifies :run, "execute[update initramfs]", :delayed
+ end
+
+ action_unload
end
action :disable do
description "Disable a kernel module."
- file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
- content "install #{new_resource.modname} /bin/false"
- notifies :run, "execute[update initramfs]", :delayed
- end
-
with_run_context :root do
find_resource(:execute, "update initramfs") do
command initramfs_command
@@ -168,7 +164,12 @@ class Chef
end
end
- new_resource.run_action(:unload)
+ file "#{new_resource.unload_dir}/disable_#{new_resource.modname}.conf" do
+ content "install #{new_resource.modname} /bin/false"
+ notifies :run, "execute[update initramfs]", :delayed
+ end
+
+ action_unload
end
action :load do
diff --git a/lib/chef/resource/locale.rb b/lib/chef/resource/locale.rb
index 2aba948b5d..ea62a0d6b2 100644
--- a/lib/chef/resource/locale.rb
+++ b/lib/chef/resource/locale.rb
@@ -1,6 +1,6 @@
#
# Copyright:: 2011-2016, Heavy Water Software Inc.
-# Copyright:: 2016-2018, Chef Software Inc.
+# Copyright:: 2016-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ require_relative "../dist"
class Chef
class Resource
class Locale < Chef::Resource
+ unified_mode true
resource_name :locale
description "Use the locale resource to set the system's locale."
@@ -66,12 +67,10 @@ class Chef
action :update do
description "Update the system's locale."
- begin
- unless up_to_date?
- converge_by "Updating System Locale" do
- generate_locales unless unavailable_locales.empty?
- update_locale
- end
+ unless up_to_date?
+ converge_by "Updating System Locale" do
+ generate_locales unless unavailable_locales.empty?
+ update_locale
end
end
end
diff --git a/lib/chef/resource/macos_userdefaults.rb b/lib/chef/resource/macos_userdefaults.rb
index 02d65baee4..4197f3a0a8 100644
--- a/lib/chef/resource/macos_userdefaults.rb
+++ b/lib/chef/resource/macos_userdefaults.rb
@@ -1,6 +1,6 @@
#
# Copyright:: 2011-2018, Joshua Timberman
-# Copyright:: 2018, Chef Software, Inc.
+# Copyright:: 2018-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ require_relative "../resource"
class Chef
class Resource
class MacosUserDefaults < Chef::Resource
+ unified_mode true
+
# align with apple's marketing department
resource_name :macos_userdefaults
provides(:mac_os_x_userdefaults) { true }
@@ -106,7 +108,9 @@ class Chef
cmd << "-#{type}" if type
cmd << value
- declare_resource(:execute, cmd.join(" ")) do
+ # FIXME: this should use cmd directly as an array argument, but then the quoting
+ # of indiviual args above needs to be removed as well.
+ execute cmd.join(" ") do
user new_resource.user unless new_resource.user.nil?
end
end
diff --git a/lib/chef/resource/macosx_service.rb b/lib/chef/resource/macosx_service.rb
index 6c055a1ee9..fc3b269c24 100644
--- a/lib/chef/resource/macosx_service.rb
+++ b/lib/chef/resource/macosx_service.rb
@@ -21,6 +21,8 @@ require_relative "service"
class Chef
class Resource
class MacosxService < Chef::Resource::Service
+ unified_mode true
+
resource_name :macosx_service
provides :macosx_service
provides :service, os: "darwin"
diff --git a/lib/chef/resource/sudo.rb b/lib/chef/resource/sudo.rb
index 3be06fa367..4ee3ef93f4 100644
--- a/lib/chef/resource/sudo.rb
+++ b/lib/chef/resource/sudo.rb
@@ -4,7 +4,7 @@
#
# Copyright:: 2011-2018, Bryan w. Berry
# Copyright:: 2012-2018, Seth Vargo
-# Copyright:: 2015-2018, Chef Software, Inc.
+# Copyright:: 2015-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,8 @@ require_relative "../resource"
class Chef
class Resource
class Sudo < Chef::Resource
+ unified_mode true
+
resource_name :sudo
provides(:sudo) { true }
@@ -148,14 +150,13 @@ class Chef
validate_properties
if docker? # don't even put this into resource collection unless we're in docker
- declare_resource(:package, "sudo") do
- action :nothing
+ package "sudo" do
not_if "which sudo"
- end.run_action(:install)
+ end
end
target = "#{new_resource.config_prefix}/sudoers.d/"
- declare_resource(:directory, target) unless ::File.exist?(target)
+ directory(target) unless ::File.exist?(target)
Chef::Log.warn("#{new_resource.filename} will be rendered, but will not take effect because the #{new_resource.config_prefix}/sudoers config lacks the includedir directive that loads configs from #{new_resource.config_prefix}/sudoers.d/!") if ::File.readlines("#{new_resource.config_prefix}/sudoers").grep(/includedir/).empty?
file_path = "#{target}#{new_resource.filename}"
@@ -163,7 +164,7 @@ class Chef
if new_resource.template
logger.trace("Template property provided, all other properties ignored.")
- declare_resource(:template, file_path) do
+ template file_path do
source new_resource.template
mode "0440"
variables new_resource.variables
@@ -171,7 +172,7 @@ class Chef
action :create
end
else
- declare_resource(:template, file_path) do
+ template file_path do
source ::File.expand_path("../support/sudoer.erb", __FILE__)
local true
mode "0440"
diff --git a/lib/chef/resource/timezone.rb b/lib/chef/resource/timezone.rb
index 16a7f1031e..b34b0a077b 100644
--- a/lib/chef/resource/timezone.rb
+++ b/lib/chef/resource/timezone.rb
@@ -2,7 +2,7 @@
# Author:: Kirill Kouznetsov <agon.smith@gmail.com>
#
# Copyright 2018, Kirill Kouznetsov.
-# Copyright 2018, Chef Software, Inc.
+# Copyright 2018-2020, Chef Software Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@ require_relative "../resource"
class Chef
class Resource
class Timezone < Chef::Resource
+ unified_mode true
+
resource_name :timezone
description "Use the timezone resource to change the system timezone on Windows, Linux, and macOS hosts. Timezones are specified in tz database format, with a complete list of available TZ values for Linux and macOS here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones and for Windows here: https://ss64.com/nt/timezones.html."
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index d1d63e64c8..0102a62a2f 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -1,6 +1,6 @@
#
# Author:: AJ Christensen (<aj@chef.io>)
-# Copyright:: Copyright 2008-2018, Chef Software Inc.
+# Copyright:: Copyright 2008-2020, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,6 +22,8 @@ require_relative "../dist"
class Chef
class Resource
class YumPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :yum_package
provides :package, platform_family: "fedora_derived"
diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb
index 3e4bff4cd7..d427ee60c8 100644
--- a/lib/chef/resource/zypper_package.rb
+++ b/lib/chef/resource/zypper_package.rb
@@ -20,8 +20,9 @@ require_relative "package"
class Chef
class Resource
-
class ZypperPackage < Chef::Resource::Package
+ unified_mode true
+
resource_name :zypper_package
provides :package, platform_family: "suse"