Class: Chef::Provider::Group::Groupadd
- Inherits:
-
Chef::Provider::Group
- Object
- Chef::Provider
- Chef::Provider::Group
- Chef::Provider::Group::Groupadd
- Defined in:
- lib/chef/provider/group/groupadd.rb
Instance Attribute Summary
Attributes inherited from Chef::Provider::Group
Attributes inherited from Chef::Provider
#action, #current_resource, #new_resource, #run_context
Instance Method Summary collapse
-
#create_group ⇒ Object
Create the group.
- #define_resource_requirements ⇒ Object
- #groupadd_options ⇒ Object
- #load_current_resource ⇒ Object
-
#manage_group ⇒ Object
Manage the group when it already exists.
- #modify_group_members ⇒ Object
-
#remove_group ⇒ Object
Remove the group.
- #required_binaries ⇒ Object
-
#set_options ⇒ Object
Little bit of magic as per Adam’s useradd provider to pull the assign the command line flags.
Methods inherited from Chef::Provider::Group
#action_create, #action_manage, #action_modify, #action_remove, #compare_group, #initialize, #whyrun_supported?
Methods included from Mixin::Command
#chdir_or_tmpdir, #handle_command_failures, #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, #cleanup_after_converge, #cookbook_name, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?, #whyrun_supported?
Methods included from DSL::Recipe
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
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::DSL::Recipe
Instance Method Details
#create_group ⇒ Object
Create the group
46 47 48 49 50 51 52 |
# File 'lib/chef/provider/group/groupadd.rb', line 46 def create_group command = "groupadd" command << command << run_command(:command => command) modify_group_members end |
#define_resource_requirements ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/chef/provider/group/groupadd.rb', line 34 def define_resource_requirements super required_binaries.each do |required_binary| requirements.assert(:all_actions) do |a| a.assertion { ::File.exists?(required_binary) } a. 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 end |
#groupadd_options ⇒ Object
87 88 89 90 91 |
# File 'lib/chef/provider/group/groupadd.rb', line 87 def opts = '' opts << " -r" if @new_resource.system opts end |
#load_current_resource ⇒ Object
30 31 32 |
# File 'lib/chef/provider/group/groupadd.rb', line 30 def load_current_resource super end |
#manage_group ⇒ Object
Manage the group when it already exists
55 56 57 58 59 60 |
# File 'lib/chef/provider/group/groupadd.rb', line 55 def manage_group command = "groupmod" command << run_command(:command => command) modify_group_members end |
#modify_group_members ⇒ Object
67 68 69 |
# File 'lib/chef/provider/group/groupadd.rb', line 67 def modify_group_members raise Chef::Exceptions::Group, "you must override modify_group_members in #{self.to_s}" end |
#remove_group ⇒ Object
Remove the group
63 64 65 |
# File 'lib/chef/provider/group/groupadd.rb', line 63 def remove_group run_command(:command => "groupdel #{@new_resource.group_name}") end |
#required_binaries ⇒ Object
24 25 26 27 28 |
# File 'lib/chef/provider/group/groupadd.rb', line 24 def required_binaries [ "/usr/sbin/groupadd", "/usr/sbin/groupmod", "/usr/sbin/groupdel" ] end |
#set_options ⇒ Object
Little bit of magic as per Adam’s useradd provider to pull the assign the command line flags
Returns
- <string>
-
A string containing the option and then the quoted value
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/chef/provider/group/groupadd.rb', line 74 def 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_s} to #{@new_resource.send(field)}") end end end opts << " #{@new_resource.group_name}" end |