Ask Your Question

Fact will only be set correctly after two runs (dynamic calculation via python script) [closed]

asked 2017-10-11 04:19:34 -0600

mknl gravatar image


I'm fighting a little bit with setting some dynamically calculated kernel parameters on RHEL (7) systems using a ruby file. In my structure the files are under <my_kernel_param_setting_module>/lib/facter/<my_kernel_parameter>.rb (what should be correct as it works at least after the second run). Content of this file:

require 'facter'
Facter.add("<my_kernel_parameter>") do
      confine :kernel => :linux, :operatingsystem => %w{CentOS Fedora RedHat}
      setcode do

So now I'm wondering why this only works when puppet runs twice. I already put the script (which calculates the value dynamically) distribution to another module so that it is definitively there when this module (where factor has to set this parameter) runs. These two modules are configured that they depend on each other of course. In metadata.json of the <my_kernel_param_setting_module>:

  "dependencies": [
    {"name":"puppetlabs-stdlib","version_requirement":">= 1.0.0"},
    {"name":"<my_dynamic_kernel_param_value_calc_script_distribution_module>","version_requirement":">= 0.1.2"}

But this does not change anything. Still two runs are necessary that it works correctly.

Does anyone have a tip for me?

Thanks in advance

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by mknl
close date 2017-10-18 08:37:18.445262


Does your puppet run do something to change the configuration that the fact is checking? Facts are run once before any catalog changes are applied. No matter how many times you call the fact, you are just referencing the cached output.

DarylW gravatar imageDarylW ( 2017-10-11 09:23:46 -0600 )edit

Thanks DarylW for your hint. Can you re-word this "Does your puppet run do something to change the configuration that the fact is checking? Facts are run once before any catalog changes are applied. " a little bit?

mknl gravatar imagemknl ( 2017-10-12 02:49:09 -0600 )edit

I though it is enought to split it into two modules. Facts will not be set module by module?

mknl gravatar imagemknl ( 2017-10-12 02:49:18 -0600 )edit

You can put facts in multiple modules, but they will all be run ‘at once’, the results of the run are sent back to the master, and that single set of results will be used no matter how often your puppet code calls the facts, in one or many modules.

DarylW gravatar imageDarylW ( 2017-10-12 07:21:50 -0600 )edit

Ok, so I think then the question is how to set the facts (including this dynamical calculated on) before the rest of the code will be applied. Or is there no way around two runs? 1. somehow push the calc-python-script to the host 2. enforce the facts will be set/reset 3. execute the rest of the code

mknl gravatar imagemknl ( 2017-10-12 07:40:09 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-10-18 08:37:08 -0600

mknl gravatar image

So the solution for this problem is the use of external facts: (3.8 is our puppet version). Thanks DarylW for the hint.

We simply have to put our python scripts with the dynamic kernel setting calculation under:


Just ensure that the values are correctly provided as key-value pair to standard out (see documention).

The difference is that the scripts under facts.d will be available on the host before and run together with factor at the beginning of a puppet run and so you can use the values (facts) later on as paramters in your classes. (in comparsion to distribute the python-scripts with file which needs two puppet runs until the script can really be used this is the smarter solution).

Additionaly this elimitnates the necessity of a second module for the script distribution (defining dependencies etc. ...). -> Which did not help either way.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-10-11 04:19:34 -0600

Seen: 80 times

Last updated: Oct 18 '17