# How to use ENC parameters as facts?

Well, the title says it all.

I use ENC. I have set some parameters there. I want to filter my nodes from PuppetDB using those parameters. Hence, I need them to become facts which will be queryable from PuppetDB.

I'd prefer not to create one custom fact per parameter, as they may change.

edit retag close merge delete

Sort by » oldest newest most voted

Ok, the only way I've found so far is not very elegant to say the least. It goes like this:

Let your ENC return something like this:

...
parameters:
foo: bar
...


Now I want a fact named "foo" with the value "bar". This should be queryable from PuppetDB and every Dashboard like PanoPuppet (it's nice). So I can filter on nodes with the value "bar".

So, create a new class. This must be included on ALL nodes:

class common::encparameter {
case $::osfamily { # better do this with hiera 'windows' : {$path = 'C:/encparameter.conf' }
default : { $path = '/root/encparameter.conf' } } file {$path:
ensure => present,
content => "\${::foo}",
}
}


Now we have the ENC parameter written to a file in a known location. To make a fact out of it, create a file "encparameter.rb" (ruby code) inside {Modulepath}/{Modulename}/lib/facter. For stuff like this, I have a module "common", so the path would be like /etc/puppet/modules/common/lib/facter/encparameter.rb.

The file looks like this: (I've never written ruby before, so be kind)

Facter.add(:foo) do
confine :osfamily => "Windows"
setcode do
end
end
confine :kernel => "Linux"
setcode do
end
end


I would appreciate every way to make this better, easier, shorter and more flexible.

Puppet needs to run two times for the fact to appear. The first run will generate the file encparameter.conf, the second run will provide the file contents as a queryable fact. Since the facts are generated first, two runs are necessary.

more