Skip to content

Instantly share code, notes, and snippets.

@towo
Created November 22, 2017 14:24
Show Gist options
  • Save towo/f178da5a80e98c0d53adc2f6074666c8 to your computer and use it in GitHub Desktop.
Save towo/f178da5a80e98c0d53adc2f6074666c8 to your computer and use it in GitHub Desktop.
Puppet fact to list all users in /etc/passwd
require 'facter'
Facter.add(:users) do
setcode do
users = []
File.open('/etc/passwd', 'r').readlines.each do |line|
if /^[^#:]+:[^:]+:[^:]+:[^:]+:[^:]+:[^:]+:[^:]+$/.match?(line)
users.push(line[/^(?<user>[^:]+)/, 'user'])
end
end
users
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment