Class: Resource::Group

Inherits:
Base
  • Object
show all
Defined in:
lib/resource/group.rb

Instance Method Summary collapse

Methods inherited from Base

inherited, #not_if, #set_base_defaults, #should_skip?, #unix_mode

Methods included from ClassAttr

included

Methods included from BlockAttr

included

Constructor Details

#initialize(groupname, &block) ⇒ Group

Returns a new instance of Group.



7
8
9
10
11
# File 'lib/resource/group.rb', line 7

def initialize groupname, &block
  set_base_defaults
  @groupname = groupname
  self.instance_eval(&block)
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/resource/group.rb', line 13

def run
  Execution.block 'Creating new group', @groupname, 'root' do |b|
    b.always_run @always_run
    groups = `cat /etc/group | cut -d: -f1`
    groups = groups.scan(/[a-zA-Z\-_]+/)
    if groups.include? @groupname
      Output.warn 'Aborted, I think this group already exists', groups.inspect
    else
      b.run "groupadd -g #{@gid} #{@groupname}"
    end
  end
end