Skip to content

Instantly share code, notes, and snippets.

@danreedy
Last active March 4, 2016 22:33
Show Gist options
  • Save danreedy/10724197 to your computer and use it in GitHub Desktop.
Save danreedy/10724197 to your computer and use it in GitHub Desktop.
Puppet Facter Custom Facts
require 'facter'
Facter.add(:current_users) do
setcode do
output = Facter::Util::Resolution.exec(%q{/usr/bin/w -h | grep console | /usr/bin/awk -F" " '{ print $1 }'})
output.gsub(/\n/,'::').split('::').uniq.join(',') # Convert the individual line output to a comma list w/ unique values
end
end
require 'facter'
Facter.add(:user_groups) do
setcode do
current_user = Facter.value(:current_users)
Facter::Util::Resolution.exec(%Q{/usr/bin/id -Gn #{current_users} | sed -e 's/\ /,/g'})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment