diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-12-20 16:02:14 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-12-20 16:02:14 -0800 |
commit | 0d1c3fcd9b866f241464219c99c2274fd5a8ca9b (patch) | |
tree | 0c2753e13aab0ff505a53e1d5715949fbee9b349 /lib/chef/provider/group/groupadd.rb | |
parent | 2628f2dd6232856af02b25c680d9a3e3e1220be5 (diff) | |
download | chef-0d1c3fcd9b866f241464219c99c2274fd5a8ca9b.tar.gz |
fix groupadd specs and modernize
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/provider/group/groupadd.rb')
-rw-r--r-- | lib/chef/provider/group/groupadd.rb | 53 |
1 files changed, 25 insertions, 28 deletions
diff --git a/lib/chef/provider/group/groupadd.rb b/lib/chef/provider/group/groupadd.rb index d7a41fb4a7..53eb3ec626 100644 --- a/lib/chef/provider/group/groupadd.rb +++ b/lib/chef/provider/group/groupadd.rb @@ -36,7 +36,7 @@ class Chef required_binaries.each do |required_binary| requirements.assert(:all_actions) do |a| a.assertion { ::File.exists?(required_binary) } - a.failure_message Chef::Exceptions::Group, "Could not find binary #{required_binary} for #{@new_resource}" + a.failure_message Chef::Exceptions::Group, "Could not find binary #{required_binary} for #{new_resource}" # No whyrun alternative: this component should be available in the base install of any given system that uses it end end @@ -44,54 +44,49 @@ class Chef # Create the group def create_group - command = "groupadd" - command << set_options - command << groupadd_options shell_out_compact!("groupadd", set_options, groupadd_options) modify_group_members end # Manage the group when it already exists def manage_group - command = "groupmod" - command << set_options shell_out_compact!("groupmod", set_options) modify_group_members end # Remove the group def remove_group - shell_out!("groupdel", new_resource.group_name) + shell_out_compact!("groupdel", new_resource.group_name) end def modify_group_members - if @new_resource.append - if @new_resource.members && !@new_resource.members.empty? + if new_resource.append + if new_resource.members && !new_resource.members.empty? members_to_be_added = [ ] - @new_resource.members.each do |member| - members_to_be_added << member if !@current_resource.members.include?(member) + new_resource.members.each do |member| + members_to_be_added << member if !current_resource.members.include?(member) end members_to_be_added.each do |member| - Chef::Log.debug("#{@new_resource} appending member #{member} to group #{@new_resource.group_name}") + Chef::Log.debug("#{new_resource} appending member #{member} to group #{new_resource.group_name}") add_member(member) end end - if @new_resource.excluded_members && !@new_resource.excluded_members.empty? + if new_resource.excluded_members && !new_resource.excluded_members.empty? members_to_be_removed = [ ] - @new_resource.excluded_members.each do |member| - members_to_be_removed << member if @current_resource.members.include?(member) + new_resource.excluded_members.each do |member| + members_to_be_removed << member if current_resource.members.include?(member) end members_to_be_removed.each do |member| - Chef::Log.debug("#{@new_resource} removing member #{member} from group #{@new_resource.group_name}") + Chef::Log.debug("#{new_resource} removing member #{member} from group #{new_resource.group_name}") remove_member(member) end end else - members_description = @new_resource.members.empty? ? "none" : @new_resource.members.join(", ") - Chef::Log.debug("#{@new_resource} setting group members to: #{members_description}") - set_members(@new_resource.members) + members_description = new_resource.members.empty? ? "none" : new_resource.members.join(", ") + Chef::Log.debug("#{new_resource} setting group members to: #{members_description}") + set_members(new_resource.members) end end @@ -112,23 +107,25 @@ class Chef # ==== Returns # <string>:: A string containing the option and then the quoted value def set_options - opts = "" + opts = [] { :gid => "-g" }.sort { |a, b| a[0] <=> b[0] }.each do |field, option| - if @current_resource.send(field) != @new_resource.send(field) - if @new_resource.send(field) - opts << " #{option} '#{@new_resource.send(field)}'" - Chef::Log.debug("#{@new_resource} set #{field} to #{@new_resource.send(field)}") + if current_resource.send(field) != new_resource.send(field) + if new_resource.send(field) + opts << option + opts << "'#{new_resource.send(field)}'" + Chef::Log.debug("#{new_resource} set #{field} to #{new_resource.send(field)}") end end end - opts << " #{@new_resource.group_name}" + opts << new_resource.group_name + opts end def groupadd_options - opts = "" + opts = [] # Solaris doesn't support system groups. - opts << " -r" if @new_resource.system && !node.platform?("solaris2") - opts << " -o" if @new_resource.non_unique + opts << "-r" if new_resource.system && !node.platform?("solaris2") + opts << "-o" if new_resource.non_unique opts end |