summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-22 09:43:36 -0700
committerTim Smith <tsmith@chef.io>2018-03-22 09:43:36 -0700
commit0938c0cecd5d2da3e117f78ed9d13c9e9f0e235f (patch)
tree72af98ec8689265c6b0e5826d71eba0f4a2bf596
parent65d26d53a70a7813c36e29f819868aadacd612f9 (diff)
downloadchef-0938c0cecd5d2da3e117f78ed9d13c9e9f0e235f.tar.gz
sudo: Don't fail on FreeBSD. Turns out there's a .d directory
I guess they use .d directory structures in sudo, but that's about it. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/sudo.rb13
-rw-r--r--spec/unit/resource/sudo_spec.rb5
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/chef/resource/sudo.rb b/lib/chef/resource/sudo.rb
index d9d61338a8..e2425f811b 100644
--- a/lib/chef/resource/sudo.rb
+++ b/lib/chef/resource/sudo.rb
@@ -104,7 +104,7 @@ class Chef
property :config_prefix, String,
description: "The directory containing the sudoers config file.",
- default: lazy { "config_prefix" }
+ default: lazy { platform_config_prefix }
alias_method :user, :users
alias_method :group, :groups
@@ -119,10 +119,12 @@ class Chef
end
# default config prefix paths based on platform
- def config_prefix
+ def platform_config_prefix
case node["platform_family"]
when "smartos"
"/opt/local/etc"
+ when "freebsd"
+ "/usr/local/etc"
when "mac_os_x"
"/private/etc"
else
@@ -133,7 +135,6 @@ class Chef
action :create do
description "Create a single sudoers config in the sudoers.d directory"
- validate_platform
validate_properties
if docker? # don't even put this into resource collection unless we're in docker
@@ -201,12 +202,6 @@ class Chef
end
action_class do
- # Make sure we fail on FreeBSD
- def validate_platform
- return unless platform_family?("freebsd")
- raise "The sudo resource cannot run on FreeBSD as FreeBSD does not support using a sudoers.d config directory."
- end
-
# Ensure that the inputs are valid (we cannot just use the resource for this)
def validate_properties
# if group, user, env_keep_add, env_keep_subtract and template are nil, throw an exception
diff --git a/spec/unit/resource/sudo_spec.rb b/spec/unit/resource/sudo_spec.rb
index 660eb285da..8f5103597c 100644
--- a/spec/unit/resource/sudo_spec.rb
+++ b/spec/unit/resource/sudo_spec.rb
@@ -80,6 +80,11 @@ describe Chef::Resource::Sudo do
expect(resource.config_prefix).to eql("/private/etc")
end
+ it "it sets the config prefix to /usr/local/etc on FreeBSD" do
+ node.automatic[:platform_family] = "freebsd"
+ expect(resource.config_prefix).to eql("/usr/local/etc")
+ end
+
it "it sets the config prefix to /opt/local/etc on smartos" do
node.automatic[:platform_family] = "smartos"
expect(resource.config_prefix).to eql("/opt/local/etc")