Class: Chef::Provider::Group::Pw
- Inherits:
-
Chef::Provider::Group
- Object
- Chef::Provider
- Chef::Provider::Group
- Chef::Provider::Group::Pw
- Defined in:
- lib/chef/provider/group/pw.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider::Group
Attributes inherited from Chef::Provider
#current_resource, #new_resource, #run_context
Instance Method Summary collapse
-
#create_group ⇒ Object
Create the group.
- #load_current_resource ⇒ Object
-
#manage_group ⇒ Object
Manage the group when it already exists.
-
#remove_group ⇒ Object
Remove the group.
-
#set_members_option ⇒ Object
Set the membership option depending on the current resource states.
-
#set_options ⇒ Object
Little bit of magic as per Adam’s useradd provider to pull and assign the command line flags.
Methods inherited from Chef::Provider::Group
#action_create, #action_manage, #action_modify, #action_remove, #compare_group, #initialize
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #not_if, #only_if, #output_of_command, #run_command, #run_command_with_systems_locale
Methods included from Mixin::Command::Windows
Methods included from Mixin::Command::Unix
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #cookbook_name, #initialize, #node, #resource_collection
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #search, #value_for_platform
Constructor Details
This class inherits a constructor from Chef::Provider::Group
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#create_group ⇒ Object
Create the group
30 31 32 33 34 35 |
# File 'lib/chef/provider/group/pw.rb', line 30 def create_group command = "pw groupadd" command << command << set_members_option run_command(:command => command) end |
#load_current_resource ⇒ Object
24 25 26 27 |
# File 'lib/chef/provider/group/pw.rb', line 24 def load_current_resource super raise Chef::Exceptions::Group, "Could not find binary /usr/sbin/pw for #{@new_resource}" unless ::File.exists?("/usr/sbin/pw") end |
#manage_group ⇒ Object
Manage the group when it already exists
38 39 40 41 42 43 |
# File 'lib/chef/provider/group/pw.rb', line 38 def manage_group command = "pw groupmod" command << command << set_members_option run_command(:command => command) end |
#remove_group ⇒ Object
Remove the group
46 47 48 |
# File 'lib/chef/provider/group/pw.rb', line 46 def remove_group run_command(:command => "pw groupdel #{@new_resource.group_name}") end |
#set_members_option ⇒ Object
Set the membership option depending on the current resource states
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/chef/provider/group/pw.rb', line 64 def set_members_option opt = "" unless @new_resource.members.empty? opt << " -M #{@new_resource.members.join(',')}" Chef::Log.debug("#{@new_resource}: setting group members to #{@new_resource.members.join(', ')}") else # New member list is empty so we should delete any old group members unless @current_resource.members.empty? opt << " -d #{@current_resource.members.join(',')}" Chef::Log.debug("#{@new_resource}: removing group members #{@current_resource.members.join(', ')}") else Chef::Log.debug("#{@new_resource}: not changing group members, the group has no members") end end opt end |
#set_options ⇒ Object
Little bit of magic as per Adam’s useradd provider to pull and assign the command line flags
Returns
- <string>
-
A string containing the option and then the quoted value
54 55 56 57 58 59 60 61 |
# File 'lib/chef/provider/group/pw.rb', line 54 def opts = " #{@new_resource.group_name}" if @new_resource.gid && (@current_resource.gid != @new_resource.gid) Chef::Log.debug("#{@new_resource}: current gid (#{@current_resource.gid}) doesnt match target gid (#{@new_resource.gid}), changing it") opts << " -g '#{@new_resource.gid}'" end opts end |