On 12/05/2012 10:22 AM, Andrew Beresford wrote:
> I've ended up separating the template into an external file and then doing
> something horrible;
>
> out=scope.to_hash.reject { |k,v| k.to_s =~
> /(uptime.*|timestamp|.*free|macaddress.*|ipaddress)/ }.to_yaml.split "\n"
> header = out.shift
> header = header+"\n"
> sorted = out.sort
> sorted_string = sorted.join "\n"
> header << sorted_string
>
> This only works because the structure of the facts.yaml content is very simple,
> and I'd much rather replace it with something more elegant.
>
> I was originally trying to override the Hash to_yaml method to output the keys
> in alphabetical order, but I ended up fighting with it too much and gave up as I
> had other more important stuff to work on.
I had the same problem and tried an equally ugly hack which worked until the
yaml started containing perfectly legal yaml anchors and aliases (&id001 and
*id001)[1]. My current solution is:
cron {
'generate_facts':
command => '/usr/bin/facter --puppet --yaml >
/etc/mcollective/facter.yaml 2> /dev/null',
minute => '0';
}
This does miss the puppet variables in the current scope (move to custom fact?)
and potentially quickly changing facts (handled with facter_dot_d?). But this
works for my needs. If anyone has a better idea I would be very interested.
[1]:
http://yaml.org/spec/1.2/spec.html#id2760395
--
Konrad Scherer, Sr. Engineer, Linux Products Group, Wind River
direct
613-963-1342 fax
613-592-2283