Created
November 22, 2017 14:24
-
-
Save towo/f178da5a80e98c0d53adc2f6074666c8 to your computer and use it in GitHub Desktop.
Puppet fact to list all users in /etc/passwd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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