Ask Your Question
0

overriding foreman parameters via custom puppet fact

asked 2015-10-02 23:15:36 -0600

gabotx gravatar image

Is this possible? Currently we have the following layout

foreman global default paramenter $param = 'a'

I want to override this value for some hosts using a puppet custom fact

    Facter.add('param') do
  setcode do
    fqdn = Facter.value(:fqdn)
    if fqdn =~ /^some regex$/
       "b"
    end
  end
end

When I test the custom fact using facter -p I get the expected result. With that said however when I use the value of $param in one of our manifests, it looks like the value of $param defined in foreman takes precedence. Is there a way to get this to work without manually overriding the value of param inside foreman itself for each host that we need to have a value different than the default?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-10-03 16:52:26 -0600

lupin gravatar image

You might be able work-around with a custom fact that return the value of your wanted setting and put a conditional clause to set it on your manifest(untested code below).

e.g.
 on manifest
      if $::fqdn =~ /foo/ {
         $param = $::wanted_setting
      } 

on custom fact
    Facter.add('wanted_setting') do
     confine :fqdn =~ /^somefqdn/
      setcode do
           "b"    
      end
    end
edit flag offensive delete link more
0

answered 2015-10-05 03:44:56 -0600

domcleal gravatar image

To add to lupin's answer, using a conditional in the manifest is the correct approach. An ENC parameter will take precedence over a fact.

It's easiest to rename the fact, so on some nodes they receive the default parameter, plus the fact. If the fact is present, use that value instead as $real_setting:

$real_setting = $wanted_setting_fact ? {
                  undef   => $wanted_setting,
                  default => $wanted_setting_fact,
                }

Or you may even be able to do the same with the $facts hash, preferring $facts['wanted_setting'] if it exists.

Otherwise in Foreman, put these hosts into a host group and then override the parameter once there. All hosts in that group will inherit that value. (Parameters on operating systems, domains, locations, organisations etc. will all override global parameters too.)

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

2 followers

Stats

Asked: 2015-10-02 23:15:36 -0600

Seen: 916 times

Last updated: Oct 05 '15