diff options
author | Tim Smith <tsmith@chef.io> | 2019-02-06 10:51:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-06 10:51:19 -0800 |
commit | 3ffccac0acebffee22257c62e41902d83b7e3335 (patch) | |
tree | 198325ff28431601e049de8ced708f5b618bdc5a /lib/chef/provider | |
parent | 7674898ca6dbdf583708eb092fd107961793d12d (diff) | |
parent | 3dcacafb63ec280cb3db7dafd37230624b09ae65 (diff) | |
download | chef-3ffccac0acebffee22257c62e41902d83b7e3335.tar.gz |
Merge pull request #8165 from jjustice6/solaris_usermod
Create a separate Group provider for Solaris systems.
Diffstat (limited to 'lib/chef/provider')
-rw-r--r-- | lib/chef/provider/group/solaris.rb | 74 | ||||
-rw-r--r-- | lib/chef/provider/group/usermod.rb | 4 |
2 files changed, 75 insertions, 3 deletions
diff --git a/lib/chef/provider/group/solaris.rb b/lib/chef/provider/group/solaris.rb new file mode 100644 index 0000000000..f5df203b78 --- /dev/null +++ b/lib/chef/provider/group/solaris.rb @@ -0,0 +1,74 @@ +# +# Author:: Joshua Justice (<jjustice6@bloomberg.net>) +# Copyright:: Copyright 2008-2019, Chef Software Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require "chef/provider/group/groupadd" + +class Chef + class Provider + class Group + class Solaris < Chef::Provider::Group::Groupadd + + # this provides line is setup to only catch the solaris2 platform, but + # NOT other platforms in the Solaris platform_family. (See usermod provider.) + provides :group, platform: "solaris2" + + def load_current_resource + super + end + + def define_resource_requirements + super + + requirements.assert(:all_actions) do |a| + a.assertion { ::File.exist?("/usr/sbin/usermod") } + a.failure_message Chef::Exceptions::Group, "Could not find binary /usr/sbin/usermod for #{new_resource}" + # No whyrun alternative: this component should be available in the base install of any given system that uses it + end + + requirements.assert(:modify, :manage) do |a| + a.assertion { (new_resource.members.empty? && new_resource.excluded_members.empty?) || new_resource.append } + a.failure_message Chef::Exceptions::Group, "setting group members directly is not supported by #{self}, must set append true in group" + # No whyrun alternative - this action is simply not supported. + end + end + + def set_members(members) + unless members.empty? + members.each do |member| + add_member(member) + end + end + unless excluded_members.empty? + excluded_members.each do |excluded_member| + remove_member(excluded_member) + end + end + end + + def add_member(member) + shell_out!("usermod", "-G", "+#{new_resource.group_name}", member) + end + + def remove_member(member) + shell_out!("usermod", "-G", "-#{new_resource.group_name}", member) + end + + end + end + end +end diff --git a/lib/chef/provider/group/usermod.rb b/lib/chef/provider/group/usermod.rb index 34a563787f..06e05ff54d 100644 --- a/lib/chef/provider/group/usermod.rb +++ b/lib/chef/provider/group/usermod.rb @@ -76,10 +76,8 @@ class Chef def append_flags case node[:platform] - when "openbsd", "netbsd", "aix", "solaris2", "smartos", "omnios" + when "openbsd", "netbsd", "aix", "smartos", "omnios" "-G" - when "solaris" - [ "-a", "-G" ] end end |