lib/puppet/provider/macgroup/default.rb
def manage_group

    name         = @resource[:name]
    comment      = @resource[:comment]  || @property_hash[:comment]
    realname     = @resource[:realname] || @property_hash[:realname]
    gid          = @resource[:gid]      || @property_hash[:gid]
    users        = @resource[:users]
    nestedgroups = @resource[:nestedgroups]

    cmd_args = ['-q', '-o']

    if @property_flush[:ensure] == :absent
      # Destroy the group
      cmd_args += ['delete', name]
      dseditgroup(cmd_args)
    else
      # Edit or Create the group
      op = :edit
      begin
        dseditgroup([cmd_args, 'read', name].flatten)
      rescue Puppet::ExecutionFailure => e
        op = :create
      end
      cmd_args << op

      # The dsmemberutil :edit operation will not edit a GID that already
      # exists, EVEN IF it belongs to the group we are editing!!! So, don't
      # try and edit the GID unless we have to. Of course, if the GID
      # being assigned to the target group already belongs to another entity,
      # a Puppet::ExecutionFailure will be raised, but that's probably a
      # good thing. Probably.
      if gid
        unless gid.to_i == @original_properties[:gid].to_i
          cmd_args += ['-i', "#{gid}"]
        end
      end

      cmd_args += ['-r', "#{realname}" ] if realname
      cmd_args += ['-c', "#{comment}"  ] if comment
      cmd_args << name

      dseditgroup(cmd_args)
      update_membership(:users)        if users
      update_membership(:nestedgroups) if nestedgroups
    end

  end
# Provider Helper method
# Create the group OR destroy it
Provider Helper method
Create the group OR destroy it
Provider Helper method Create the group OR destroy it
def manage_group
    name         = @resource[:name]
    comment      = @resource[:comment]  || @property_hash[:comment]
    realname     = @resource[:realname] || @property_hash[:realname]
    gid          = @resource[:gid]      || @property_hash[:gid]
    users        = @resource[:users]
    nestedgroups = @resource[:nestedgroups]
    cmd_args = ['-q', '-o']
    if @property_flush[:ensure] == :absent
      cmd_args += ['delete', name]
      dseditgroup(cmd_args)
    else
      op = :edit
      begin
        dseditgroup([cmd_args, 'read', name].flatten)
      rescue Puppet::ExecutionFailure => e
        op = :create
      end
      cmd_args << op
      if gid
        unless gid.to_i == @original_properties[:gid].to_i
          cmd_args += ['-i', "#{gid}"]
        end
      end
      cmd_args += ['-r', "#{realname}" ] if realname
      cmd_args += ['-c', "#{comment}"  ] if comment
      cmd_args << name
      dseditgroup(cmd_args)
      update_membership(:users)        if users
      update_membership(:nestedgroups) if nestedgroups
    end
  end
def manage_group name = @resource [ :name ] comment = @resource [ :comment ] || @property_hash [ :comment ] realname = @resource [ :realname ] || @property_hash [ :realname ] gid = @resource [ :gid ] || @property_hash [ :gid ] users = @resource [ :users ] nestedgroups = @resource [ :nestedgroups ] cmd_args = [ '-q' , '-o' ] if @property_flush [ :ensure ] == :absent cmd_args += [ 'delete' , name ] dseditgroup ( cmd_args ) else op = :edit begin dseditgroup ( [ cmd_args , 'read' , name ] . flatten ) rescue Puppet :: ExecutionFailure => e op = :create end cmd_args << op if gid unless gid . to_i == @original_properties [ :gid ] . to_i cmd_args += [ '-i' , "#{gid}" ] end end cmd_args += [ '-r' , "#{realname}" ] if realname cmd_args += [ '-c' , "#{comment}" ] if comment cmd_args << name dseditgroup ( cmd_args ) update_membership ( :users ) if users update_membership ( :nestedgroups ) if nestedgroups end end
Provider Helper method
Create the group OR destroy it
Provider Helper method Create the group OR destroy it
# Destroy the group # Edit or Create the group # The dsmemberutil :edit operation will not edit a GID that already # exists, EVEN IF it belongs to the group we are editing!!! So, don't # try and edit the GID unless we have to. Of course, if the GID # being assigned to the target group already belongs to another entity, # a Puppet::ExecutionFailure will be raised, but that's probably a # good thing. Probably.