begin
require 'etc'
- Facter.add("git_key") do
- setcode do
- key = nil
- keyfile = '/home/git/.ssh/id_rsa.pub'
- if FileTest.exist?(keyfile)
- key = File.open(keyfile).read.chomp
+ %w{git}.each do |user|
+ Facter.add("#{user}_user_exists") do
+ setcode do
+ result = false
+ begin
+ if Etc.getpwnam(user)
+ result = true
+ end
+ rescue ArgumentError
+ end
+ result
+ end
+ end
+
+ Facter.add("#{user}_key") do
+ setcode do
+ key = nil
+ begin
+ pwinfo = Etc.getpwnam(user)
+ if pwinfo and pwinfo.dir
+ keyfile = pwinfo.dir + '/.ssh/id_rsa.pub'
+ if FileTest.exist?(keyfile)
+ key = File.open(keyfile).read.chomp
+ end
+ end
+ rescue ArgumentError
+ end
+ key
end
- key
end
end