Last active
August 29, 2015 14:27
-
-
Save ares/0b90c84ac30be3a640fa to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
#!/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