Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created November 25, 2009 15:26
Show Gist options
  • Save ohadlevy/242786 to your computer and use it in GitHub Desktop.
Save ohadlevy/242786 to your computer and use it in GitHub Desktop.
module Puppet::Parser::Functions
newfunction(:sshkeyfromdb, :type => :rvalue) do |args|
#local cache file on each puppetmaster
ssh_keys_file = "/tmp/sshkeys"
#URL to query
host = "puppet"
url = "/setting/ssh_keys?script=true"
#Time to keep cache - e.g. 1 hours.
ttl = (60 * 60)
# create a cache file
if not File.exist?(ssh_keys_file) or File.mtime(ssh_keys_file) < (Time.now - ttl)
# cache miss, refreshing
keys = Net::HTTP.get host,url
File.new(ssh_keys_file,"w", 0600).write(keys)
else
keys = File.open(ssh_keys_file).read
end
return keys
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment