Fact that looks up gid of a certain group
For each gid to lookup, create a ruby file with the following contents in the appropriate location and change the group variable to match the group that should be looked up.
#!/usr/bin/env ruby
# Return the gid of a group
group = 'ftpgroup'
require 'facter'
require 'etc'
Facter.add("gid_#{group}") do
confine :kernel => :linux
setcode do
begin
Etc.getgrnam(group).gid
rescue ArgumentError
end
end
end
This might be a more elegant approach. It returns all GIDs.
#!/usr/bin/env ruby
## Return the gid of a group
require 'etc'
Etc.group { |g|
Facter.add("gid_" + g.name) do
confine :kernel => :linux
setcode do
g.gid
end
end
}
Another fact that returns each group and its members.
#!/usr/bin/env ruby
## Return a group and its members
require 'etc'
Etc.group { |g|
Facter.add("group_" + g.name) do
confine :kernel => :linux
setcode do
g.mem.join(',')
end
end
}
