Preparing for the 1.24 to 2.x upgrade I noticed smart-variables have been removed.
Extremely bummed to learn that, as it was the only somewhat nice way I could think of to get a variable that indicates which class is assigned to a host.
We use roles and profiles and lookup data in a specific layer/file based on what role has been assigned to a host.
So one of the layers in hiera is:
- name: "Puppet role"
path: "roles/%{::puppet_role}.yaml"
Then for each role I add a smart parameter to the class that sets $role_xyz = true.
And in site.pp set the $puppet_role variable based which role_xyx is defined/true.
if $role_xxx { puppet_role = "xxx" }
elsif $role_yyy { puppet_role = "yyy" }
elsif $role_zzz etc etc
The hole thing is basically a workaround for not having the (list of) class(es) assigned to a node in a variable we can use in hiera(.yaml)… but at least it worked.
How do I do this without smart variables?
Could of course just manually add a puppet_role parameter to each and every host and set it to the role assigned. But that that get’s old fast and is error prone.
Config groups maybe? Havent really looked into it but would suffer from the same issue of having to set both.
We already use hostgroups for other purposes, with an N:N relationship between hostgroups & roles.
Thought of doing it via a fact, pull the role from the classes file. But first time around it won’t be set yet, so some manifest will get data, possibly do things, that is/are wrong on on hosts with a certain role.
Anyone have another clever idea?
Note, the roles layer in hiera is not used to provide data for the role class itself, it’s more for other classes/profiles who’s data (values) depend on what role we assign. For example, say we have some base profile that does all the generic setup, including setting some sysctl settings. If hosts with a certain role need different values for some sysctl the roles/xyz.yaml provides a place to override the value for say profile::base::sysctl_settings otherwise set in some lower layer.
Regards,
Mark.