diff options
author | Phil Dibowitz <phil@ipom.com> | 2014-08-04 11:45:40 -0700 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2014-08-04 15:38:31 -0700 |
commit | fa33c10522b7ad8719e275e6f0be981c7ada348e (patch) | |
tree | a4faa39dbc4715d4d0799a39fd8c56850aed69f7 /lib/chef/provider/group/dscl.rb | |
parent | 1dc4da1720c8bdbd8f44429c6d7861d484dcd631 (diff) | |
download | chef-fa33c10522b7ad8719e275e6f0be981c7ada348e.tar.gz |
Fix OSX Group provider to be properly idempotent
Currently the OSX Group provider use the 'Etc' module to determine
what exists, and the 'dscl' command to change things. Etc will look
to /etc/group by default and fallback to 'dscl', which causes idempotency
incorrectness. This change the Group provider to simply look at 'dscl' always.
Diffstat (limited to 'lib/chef/provider/group/dscl.rb')
-rw-r--r-- | lib/chef/provider/group/dscl.rb | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lib/chef/provider/group/dscl.rb b/lib/chef/provider/group/dscl.rb index c204c09321..04ca9bc929 100644 --- a/lib/chef/provider/group/dscl.rb +++ b/lib/chef/provider/group/dscl.rb @@ -39,11 +39,33 @@ class Chef return result[2] end - # This is handled in providers/group.rb by Etc.getgrnam() - # def group_exists?(group) - # groups = safe_dscl("list /Groups") - # !! ( groups =~ Regexp.new("\n#{group}\n") ) - # end + def load_current_resource + @current_resource = Chef::Resource::Group.new(@new_resource.name) + @current_resource.group_name(@new_resource.name) + group_info = nil + begin + group_info = safe_dscl("read /Groups/#{@new_resource.name}") + rescue Chef::Exceptions::Group + @group_exists = false + Chef::Log.debug("#{@new_resource} group does not exist") + end + + if group_info + group_info.each_line do |line| + key, val = line.split(': ') + val.strip! if val + case key.downcase + when 'primarygroupid' + @new_resource.gid(val) unless @new_resource.gid + @current_resource.gid(val) + when 'groupmembership' + @current_resource.members(val.split(' ')) + end + end + end + + @current_resource + end # get a free GID greater than 200 def get_free_gid(search_limit=1000) @@ -115,10 +137,6 @@ class Chef end end - def load_current_resource - super - end - def create_group dscl_create_group set_gid |