Skip to content

Instantly share code, notes, and snippets.

@ares
Last active August 29, 2015 14:27
Show Gist options
  • Save ares/0b90c84ac30be3a640fa to your computer and use it in GitHub Desktop.
Save ares/0b90c84ac30be3a640fa to your computer and use it in GitHub Desktop.
Simple script to convert puppet text output to yaml so it can be easily uploaded to Foreman using node script.
usage:
convert_text_facts_to_yaml.rb /tmp/user.yaml > /var/lib/puppet/yaml/facts/user.yaml
/etc/puppet/node.rb user
#!/usr/bin/env ruby
require 'yaml'
require 'time'
if ARGV.size != 1
puts 'This script requires only on argument - path to the file with text output of cater'
exit 1
end
f = File.read ARGV[0]
hash = {}
f.split("\n").each do |line|
key, value = line.split('=>', 2)
next if value.nil? # SSHFP records may cause issues
if value.include?('{')
value = eval(value)
else
value = value.strip
end
hash[key.strip] = value
end
hash = {'name' => ARGV[0], 'values' => hash, 'expiration' => Time.now}
puts hash.to_yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment