Search this site


Metadata

Articles

Projects

Presentations

Puppet data into mcollective facts

There's a plugin for mcollective that lets you use puppet as your mcollective fact source. However, it doesn't seem to support the plugins-in-modules approach that puppet allows, and I don't want to have to regenerate and restart mcollective any time I add new fact modules.

Mcollective comes with a yaml fact plugin by default which will load facts from a yaml file of your choice. Exporting puppet facts in yaml format is super trivial during a puppet run:

  package {
    "mcollective": ensure => "0.4.10-1";
    ...
  }

  file {
    "/etc/mcollective/facts.yaml":
      ensure => file,
      content => inline_template("<%= scope.to_hash.reject { |k,v| !( k.is_a?(String) && v.is_a?(String) ) }.to_yaml %>"),
      require => Package["mcollective"];
  }
Easy. Now each puppet run updates will dump it's fact/parameter knowledge to that file and mcollective can use those facts:
% mc-facts lsbdistrelease
Report for fact: lsbdistrelease                            

        10.04                                   found 18 times

Finished processing 18 hosts in 5533.86 ms
An added benefit of this is that any puppet variables (not just facts!) that are in scope are included in the yaml output. This lets you write "facts" to feed mcollective and puppet from plain puppet manifests. Awesome!

Update: Looks like there's a bug/feature somewhere that causes puppet to output yaml that mcollective can't handle due to sorting problems (like '!ruby/sym _timestamp'). To solve this, filter the scope hash for keys and values that are not strings. I have updated the code above to reflect this. Future mcollective releases will handle funky data more safely.