Ask Your Question

using hiera to break off profiles for management of nodes

asked 2015-04-03 12:31:12 -0600

hellswesties gravatar image


While I am not unfamiliar with Puppet and Hiera, I have been struggling to find a solution to a design problem that seems should be easy to do, given Puppet's and Hiera's abilities. I have seen many examples of what can be done (including the Craig Dunn examples), but most are overly-complicated or not quite what I need to accomplish.

I have Puppet/Hiera set up to build and update a system based on what type of system I need. Example:

# nodes.pp
node ''
     include standard_packages
node ''
     include standard_packages
     include apache
node ''
     include standard_packages
     include dhcpd

# hiera.yaml
  - yaml
  :datadir: /etc/puppet/hierdata
  - "nodes/%{fqdn}"
  - "profiles/%{profiles}"
  - common

# common.yaml
iptables_config: 'iptables/ipconfig_common.erb'
motd_config    : 'common/motd_common.erb'

# nodes/
iptables_config: 'iptables_web.erb'
motd_config    : 'common/motd_web.erb'

# nodes/
iptables_config: 'iptables_dhcp.erb'
motd_config    : 'common/motd_host.erb'

Seems pretty straightforward, and it works this way. But it's chatty because I have to create a YAML for every system in the "nodes" directory. I want to add a "profile-based" hierarchy in Hiera such that the system would get all the configs it need depending upon what type (function) of system it is (i.e., common, web, apache, etc.). In my hierarchy, the following would exist:

# profiles/dhcpd_server.yaml
iptables_config: 'iptables_dhcp.erb'

# profiles/web_server.yaml
iptables_config: 'iptables_web.erb'
motd_config    : 'common/motd_web.erb'

This way, I don't need a YAML for every system (or just really-specific host info for that), just one for all the dhcpd servers. What I don't understand how to do is have a system know it's a "webserver" or a "dhcpdserver"..., or not.

How to I set that with Hiera?

The common.yaml basically says, "If you have this FQDN, look up that YAML and pull variables from there".

How do I get it to trickle down when it's done with the "fqdn" YAML to pick up the next in the path, the "profiles" YAML variables?

Does this explain what I'm trying to accomplish?

Thanks in advance for all the pointers.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-03 14:19:14 -0600

lavaman gravatar image

Hiera will use fact values or global variables.

You can either create a custom fact that runs on each server and returns that role, or create a global variable in site.pp that does the same.

The first method is considered better practice.

How this is determined is based on how you provision and manage your servers. It could be based on hostname and/or domain, ip address, or some other metadata that exists on the system when you build it.

Here are the docs on custom facts:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-04-03 12:31:12 -0600

Seen: 265 times

Last updated: Apr 03 '15