0

I'm reading through the Puppet Documentation on adding a custom fact. Most of the information seems related to making module that runs on the agent.

In my case I just want a simple environment variable that I could set from the master for each node. Then my ENC would make a PuppetDb query to see what environment it should serve.

Can I do this, or do all facts originate from the agent?

Philip Kirkbride
  • 279
  • 2
  • 10
  • 30
  • You might want to look into the roles and profiles model, as its one way of defining specific roles within your ENC. The example uses hiera, but it shouldn't be too hard to convert. One of the guides is at https://docs.puppet.com/pe/2017.1/r_n_p_full_example.html – Jenos May 02 '17 at 22:08
  • What ENC are you using? All facts do originate from the agent, but depending on the ENC there may be other ways to pull in relevant information. – Yozomiri May 03 '17 at 02:40
  • @yozomiri at this point my ENC is just a shell script but I'd be open to using a framework. – Philip Kirkbride May 03 '17 at 02:48

2 Answers2

1

puppet facts are always informations sent by the agent to the master. Thus you can't set a fact on the puppetmaster side.

But, you have the option to configure the agent environment with puppet receipts (for example, using [puppet_config_providers][1]).

puppet_config { 'agent/environment':
  value => $::puppet_environment,
}

However, this change would be taken into account only on the next puppet run.

[1] https://forge.puppet.com/camptocamp/puppet_config_providers

Saïmonn
  • 325
  • 2
  • 8
  • When I search "puppet receipts" it's hard to find anything. I found a puppet module you own as the top result. Can you recommend any reading to get more information on what a receipt is? – Philip Kirkbride May 04 '17 at 15:20
  • 1
    "receipt" is a way of naming the "puppet code", or files with the `.pp` extension. – Saïmonn May 04 '17 at 15:27
1

Can I do this,

Yes that is possible. One could create a custom fact in a puppet module, e.g. run some ruby code in order to get the version of installed software:

module_name/lib/facter/customfact.rb

Facter.add("customfact") do
  setcode do
    123
  end
end

The above code resides on the Puppetmaster and when puppet is run on, e.g. ten different agents, the outcome, i.e. 123 and the hostname of each node will be registered in PuppetDB and could be viewed in Puppetboard.

or do all facts originate from the agent?

No the custom facts reside on the Puppetmaster

030
  • 5,901
  • 13
  • 68
  • 110