I'm not sure of the utility of this, but maybe it'll be useful to someone else. I was requested to output all the facts from a system in xml, not wanting to type much I made the following script...


#!/usr/bin/env ruby

require 'facter'
require 'rubygems'
require 'activesupport'

Facter.loadfacts
facts = {}

for fact in Facter.list.sort
facts[fact] = Facter.value(fact)
end

xml = facts.to_xml(:root => "facts")

print xml

The output looks like the following:


<?xml version="1.0" encoding="UTF-8"?>

13139767
...
4
lmnbsd01094d02

127.0.0.0

Tikanga
x86_64

Possibly useful someday...I require activesupport, so you'll need to install that gem. That gem gives you the to_xml method for hashes.

Enjoy.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

About the Author...