Class: Chef::Provider::Group
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- Chef::Provider::Group
- Includes:
- Mixin::Command
- Defined in:
- lib/chef/provider/group.rb,
lib/chef/provider/group/pw.rb,
lib/chef/provider/group/aix.rb,
lib/chef/provider/group/dscl.rb,
lib/chef/provider/group/suse.rb,
lib/chef/provider/group/gpasswd.rb,
lib/chef/provider/group/usermod.rb,
lib/chef/provider/group/windows.rb,
lib/chef/provider/group/groupadd.rb,
lib/chef/provider/group/groupmod.rb
Defined Under Namespace
Classes: Aix, Dscl, Gpasswd, Groupadd, Groupmod, Pw, Suse, Usermod, Windows
Instance Attribute Summary collapse
-
#change_desc ⇒ Object
Returns the value of attribute change_desc.
-
#group_exists ⇒ Object
Returns the value of attribute group_exists.
Attributes inherited from Chef::Provider
#action, #current_resource, #new_resource, #run_context
Instance Method Summary collapse
- #action_create ⇒ Object
- #action_manage ⇒ Object
- #action_modify ⇒ Object
- #action_remove ⇒ Object
-
#compare_group ⇒ Object
Check to see if a group needs any changes.
- #create_group ⇒ Object
- #define_resource_requirements ⇒ Object
-
#initialize(new_resource, run_context) ⇒ Group
constructor
A new instance of Group.
- #load_current_resource ⇒ Object
- #manage_group ⇒ Object
- #remove_group ⇒ Object
- #whyrun_supported? ⇒ Boolean
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, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?
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
#initialize(new_resource, run_context) ⇒ Group
Returns a new instance of Group.
34 35 36 37 |
# File 'lib/chef/provider/group.rb', line 34 def initialize(new_resource, run_context) super @group_exists = true end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe
Instance Attribute Details
#change_desc ⇒ Object
Returns the value of attribute change_desc.
28 29 30 |
# File 'lib/chef/provider/group.rb', line 28 def change_desc @change_desc end |
#group_exists ⇒ Object
Returns the value of attribute group_exists.
27 28 29 |
# File 'lib/chef/provider/group.rb', line 27 def group_exists @group_exists end |
Instance Method Details
#action_create ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/chef/provider/group.rb', line 100 def action_create case @group_exists when false converge_by("create #{@new_resource}") do create_group Chef::Log.info("#{@new_resource} created") end else if compare_group converge_by(["alter group #{@new_resource}", @change_desc ]) do manage_group Chef::Log.info("#{@new_resource} altered") end end end end |
#action_manage ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/chef/provider/group.rb', line 126 def action_manage if @group_exists && compare_group converge_by(["manage group #{@new_resource}", @change_desc]) do manage_group Chef::Log.info("#{@new_resource} managed") end end end |
#action_modify ⇒ Object
135 136 137 138 139 140 141 142 |
# File 'lib/chef/provider/group.rb', line 135 def action_modify if compare_group converge_by(["modify group #{@new_resource}", @change_desc]) do manage_group Chef::Log.info("#{@new_resource} modified") end end end |
#action_remove ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/chef/provider/group.rb', line 117 def action_remove if @group_exists converge_by("remove group #{@new_resource}") do remove_group Chef::Log.info("#{@new_resource} removed") end end end |
#compare_group ⇒ Object
Check to see if a group needs any changes. Populate
Returns
- <true>
-
If a change is required
- <false>
-
If a change is not required
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/chef/provider/group.rb', line 74 def compare_group @change_desc = nil if @new_resource.gid != @current_resource.gid @change_desc = "change gid #{@current_resource.gid} to #{@new_resource.gid}" return true end if(@new_resource.append) missing_members = [] @new_resource.members.each do |member| next if @current_resource.members.include?(member) missing_members << member end if missing_members.length > 0 @change_desc = "add missing member(s): #{missing_members.join(", ")}" return true end else if @new_resource.members != @current_resource.members @change_desc = "replace group members with new list of members" return true end end return false end |
#create_group ⇒ Object
144 145 146 |
# File 'lib/chef/provider/group.rb', line 144 def create_group raise NotImplementedError, "subclasses of Chef::Provider::Group should define #create_group" end |
#define_resource_requirements ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/chef/provider/group.rb', line 60 def define_resource_requirements requirements.assert(:modify) do |a| a.assertion { @group_exists } a.(Chef::Exceptions::Group, "Cannot modify #{@new_resource} - group does not exist!") a.whyrun("Group #{@new_resource} does not exist. Unless it would have been created earlier in this run, this attempt to modify it would fail.") end end |
#load_current_resource ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef/provider/group.rb', line 39 def load_current_resource @current_resource = Chef::Resource::Group.new(@new_resource.name) @current_resource.group_name(@new_resource.group_name) group_info = nil begin group_info = Etc.getgrnam(@new_resource.group_name) rescue ArgumentError => e @group_exists = false Chef::Log.debug("#{@new_resource} group does not exist") end if group_info @new_resource.gid(group_info.gid) unless @new_resource.gid @current_resource.gid(group_info.gid) @current_resource.members(group_info.mem) end @current_resource end |
#manage_group ⇒ Object
148 149 150 |
# File 'lib/chef/provider/group.rb', line 148 def manage_group raise NotImplementedError, "subclasses of Chef::Provider::Group should define #manage_group" end |
#remove_group ⇒ Object
152 153 154 |
# File 'lib/chef/provider/group.rb', line 152 def remove_group raise NotImplementedError, "subclasses of Chef::Provider::Group should define #remove_group" end |
#whyrun_supported? ⇒ Boolean
30 31 32 |
# File 'lib/chef/provider/group.rb', line 30 def whyrun_supported? true end |