Ask Your Question
0

How to use ENC parameters as facts?

asked 2015-06-29 04:37:16 -0600

sinned gravatar image

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-07-01 03:05:17 -0600

sinned gravatar image

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
    File.read('C:/encparameter.conf')
  end
end
Facter.add(:foo) do
  confine :kernel => "Linux"
  setcode do
    File.read('/root/encparameter.conf')
  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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-06-29 04:37:16 -0600

Seen: 764 times

Last updated: Jul 01 '15