About puppet class parameters management

I m using some classes from Puppet Forge and the smart class parameters to define the value. I m not sure how to manage the different values (and if I should manage this in Foreman)
Typically, I want to pass a value to a class (as yaml), and this value will depend on : hostgroup, environment and a value defined in location parameters.
I think I can :

  • use a template with if/then/else or switch/case to handle all values in the smart class parameter
  • use a more simple template but use smart matcher to override values
  • define a smaller if/then/else in class parameter and override in hostgroup class parameter with another if/then/else
  • use smartmatcher in class smart parameter and in hostgroup class parameter
  • try to use something else to manage the values ? hiera ? (I dont know if it possible/recommended)

Environment doesn’t provide an overriding level so I think it s the if/then/else in template or matchs which have to manage it.

I dont know where to go if I want to avoid some problems later to manage the different places where I will/can define values and templates for my puppet classes.

Do you have any advices ?
Thanks in advance

In smart class parameter you can use erb in the value which will allow you to add ifs.
Do you mean the value will depend on hostgroup, environment and location together or change according to each one?

Smart matchers have an “and” option by using a comma.
For example: add “hostgroup,environment” to the order.
This will allow you to set an override: hostgroup,environment = A,B
which means if hostgroup=A and environment=B provide this value.

Foreman doesn’t provide values for hiera.

I’m not sure I understood the missing environment overriding level - you can add a matcher in the puppet class on environment like location.
Did you mean adding an override from the environment like hostgroup? or that environment is not a good override for you case?

There is not one recommended way which is best here, it depends on your needs.
If the template changes per hostgroup/location a simple template with overrides sounds a better fit because it’s dynamic.
If for example, you just want to put the hostgroups’s name in the template regardless of what it is maybe one value is easier to manage.

I have some value which can change following, hostgroup, environment or location, and some combinations of those. I think I will not be able to avoid some duplicates.
I understood well your answer, I will make different tries, smart matchers with ‘and’ seems useful to me.

Thanks for your explanations !