Puppet: System Administration Automated

Support

Create a fact about installed users

Problem: To generate a variable containing a list of users that are installed on the system

To generate a variable containing a list of users that are installed on the system. The variable should return a comma seperated list of non-system usernames.

This list can then be split into an array inside a manifest with DavidS' split parse function for example.

Solution

require 'puppet'

def getusers
  @users = Array.new
  Puppet::Type.type("user").instances.find_all do |user|
    @values = user.retrieve
    @users.push(user.name) unless @values[user.property(:uid)].to_i < 500
  end
  @users unless @users.empty?
end

Facter.add("users") do
  setcode do
    getusers.join(",")
  end
end
$ FACTERLIB=. facter users
nobody,aj,steven,pj,tonyj,tepono,libuuid,test1,obiwan,jaydus,test,puppet

Discussion