Search code examples
puppet

Moving Puppet Centralised Parameter Coding to Variables Based on a Local Fact


Currently everything is working. However, I’m looking to separate out environment parameters to their own file to make things more manageable.

Currently my sites.pp calls class modules:

  • envs
    • This holds all global parameter
    • This holds environment parameter via if statement using local fact,
    • ensuring correct parameters are accessible when called directly
  • Other modules
    • All via if statements and only loaded if local fact has a value of 1 set for the module

Parameters in modules reference the values located in the envs via full paths, some examples:

  • modulefile.pp
    • content => template("nagios/${envs::svos}-ncpa-cfg-${envs::nagiosncpacfgver}.epp") device => "${envs::devicecm_apps}",
  • templetefile.epp
    • <%= scope['hostname'] %>.<%= scope['domain'] %>\folder1\folder2<%= scope['envs::envshort'] %>\folder3\folder4\folder5
    • <%= scope['envs::max_que'] %>

My envs class is getting big, dangerous to update (if by multiple people) and therefore I wish to move the environment parameters out to their own sub module under envs. I’ve been evaluating changes in my development Puppet environment, but am struggling to get it to work. I have sub classes named the same as a local set fact called gen_env.

My issue being I cannot for the life of me figure out how to update the above content to enable it to work. If I update it manually direct to the variable name it does works, however getting it to use the variable is something that had eluded me to date. I have tried switching to using include in my modules to load in the setting used by that module, however I ran into the same problem of how to reference the variables when mapping the content and referring via the include using a variable e.g. ‘$nagiosncpacfgver = $::envs::myenvironmentname::nagiosncpacfgver’ and ‘include envs:: myenvironmentname’.

One way I see working (yet to be tested) is to use includes in my envs to references out the parameters in the sub class. As the content is loaded from if statements and named directly I believe this will work. I still end up with a big envs module, however all parameter are made via a unique environment value. I would prefer to have this working without having to take this path, does anyone have a solution please?


Solution

  • I’ve solved my problem by altering my approach a little. I mentioned it in my last paragraph originally.

    Basically rather then making changes to my ‘other modules’, all changes are to the envs module.

    Content of changes:

    • Sub classes created for every environment using content in envs
    • Envs updates to have include statements and param links as needed e.g. $nagiosncpacfgver = $::envs::myenvironmentname::nagiosncpacfgver

    It’s a shame there is not a variable I could use to avoid individually mapping each param as I have over 400 per environment.