Host Collections in hiera?

Latest response

Is it possible to use host collections as a hiera.conf yaml file location? I am actively using hiera now, so I have the basics working.

Such as:


:backends:
- yaml
- json
:yaml:
:datadir: /etc/puppet/hieradata
:json:
:datadir: /etc/puppet/hieradata
:hierarchy:
- "%{::clientcert}"
- "%{::sat6_host_collection01}"
- common

Responses

Chuck,

I don't believe this is possible as the host collections aren't a construct that Puppet is aware of. The hiera values are generally extracted from the node's facter information (with special cases for items such as clientcert).

Can you provide some more context around what you are working on as there may be alternate solutions.

Are you also using Host Groups / Config Groups for your Puppet configuration?

I want to apply a puppet module to a selection of hosts outside of my core configuration. Such as all the servers that need an Oracle Client installed. This group could include some hosts from different core configuration but not all. Ex: not all RHEL67 servers for the web team need an oracle client.

I need the module to be assigned in hiera based on some parameter... Right now I am including this config in individual node files under hiera (nodes/.yaml).

*note: everything is working, really just looking to streamline/improve configuations

Chuck,

I will preface this post with the fact that Puppet problems are solved in a myriad of different ways, and people seem to get quite passionate about it (and opinions of how to approach/solve problems seem to change version to version). So what I am putting forth is just a suggestion, by no means an ultimate solution!

In my experience, hiera isn't generally used for the association of classes to nodes (ie. node classification) which appears to be how you are using it. How I have generally seen hiera used is to provide parameters to already assigned classes based on environmental conditions. So you may have multiple nodes, all with the same class (role/profile.. will come to this) assigned, and hiera provides different parameter values to the same assigned classes based on an environmental condition.

Some examples using a dev/test/prod model and hiera to provide parameters.

1. You have three servers across the three environments, they all have the the same ntp_client class/profile assigned which provides the time sync capability and the class has a parameter for 'ntp_hostname. In hiera, you have logic based on environment to provide a different 'ntp_hostname' parameter to the ntp_client class depending on if it is in dev/test/prod.

2. You have web servers in development/production which have the 'webserver' profile/class applied with a parameter 'log_level'. In hiera you configure your hosts in development to provide the 'debug' or 'trace' log level for the 'log_level' parameter, but in higher environments you limit logging to 'error' in the 'log_level' parameter for example.

To assign the classes such as ntp_client/webserver mentioned above I suggest looking at the role/profile model which is often referenced in Puppet documentation. There is a good video on the topic here: https://puppetlabs.com/presentations/designing-puppet-rolesprofiles-pattern

In Satellite 6 (which I assume you are using), they provide 'Host Groups' and 'Config Groups' to model this type of configuration. I am not sure if you are already using Host Groups in combination with hiera?

So for your scenario you can have a role / host group (excuse the naming, you can no doubt provide better examples for your configuration)

Host Group: role_webserver
Included Classes:
  profile_coreconfig
  profile_webserver

Then have a different role that includes the oracle client, eg

Host Group: role_webserver_with_oc
Included Classes:
  profile_coreconfig
  profile_webserver
  profile_oracleclient

Then build up different roles based on combinations of profiles/classes you want assigned to each one. Then use hiera to provide parameters to these profiles/classes.

This may be easier said than done, I have been battling with ongoing bugs/issues in the Satellite 6.1 interface myself.

Hopefully this wasn't too far off topic!

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.