Alternative to conditional If's within profile

asked 2018-02-22 07:33:44 -0500

AHH gravatar image

Within a profile class I am facing the issue of potentially having thousands of conditional If statements for dealing with individual hosts or subsets of hosts based on specific parameters, could anyone recommend a more design friendly way of dealing with such use cases?

edit retag flag offensive close merge delete



Can you give an example of what kind of code you're looking to clean up, or what kind of logic you need to apply?

reidmv gravatar imagereidmv ( 2018-02-22 14:48:33 -0500 )edit

One pattern that I have used is to have a trusted fact on the host with a ‘role’ fact that I can use to directly ‘include’ in my default profile

DarylW gravatar imageDarylW ( 2018-02-22 22:52:17 -0500 )edit

The only other additional advice would be to learn and embrace the hierarchy in hiera - you can move your variable/state definition out into per env/region/datacenter/hostname based tiers in your hierarchy, and act according to the presence or absence of those variables.

DarylW gravatar imageDarylW ( 2018-02-23 08:53:14 -0500 )edit