Ask Your Question
1

define hiera layer in node yaml

asked 2014-10-01 06:16:50 -0500

fetch gravatar image

I'm using hiera with puppet and try to setup a hierarchy using my own variables. Setting it up using the provided facts works fine, but I would like to insert another layer using a variable which is set per node in the node yaml definition.

The use case is this: I have systems deployed in the blue zone and now want to have systems in the yellow (DMZ) zone. Therefore, they need different configs, e.g. different ntp servers. I want to achieve this, by declaring the zone in the node yaml file and not using custom facts, because the machine does not know if it's in blue or yellow zone.

My hiera.yaml looks like this:

---
:backends:
  - yaml
:hierarchy:
  - "node/%{::fqdn}"
  - "zone/%{zone}"
  - "osfamily/%{::osfamily}"
  - "common"

:yaml:
  :datadir: /etc/puppet/environments/prod/hieradata

Now, osfamily and fqdn are default fact shipped with facter and work fine. The problem is the zone, which I want to declare like this:

yellownode.yaml

---
classes:
  - user
  - admin
zone:
  - yellow

bluenode.yaml

---
classes:
  - user
  - admin
zone:
  - blue

And then zone specific yamls look like this:

zone/bluezone.yaml

---
ntpserver: ntp.bluezone.com

zone/yellowzone.yaml

---
ntpserver: ntp.yellowzone.com

This way, I can have a zone layer in my hierarchy and do not have to state the ntp server (and many other values which are zone-specific) in the node definition, but only the zone type. Is this even possible? I'm not sure if it's working like I think, so I'm open for suggestions.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-10-02 03:14:37 -0500

fetch gravatar image

I found the solution: Just edit the hiera.yaml like this:

---
:backends:
  - yaml
:hierarchy:
  - "node/%{::fqdn}"
  - "zone/%{hiera('zone')}"
  - "osfamily/%{::osfamily}"
  - "common"

:yaml:
  :datadir: /etc/puppet/environments/prod/hieradata

This way, hiera will do a lookup of the variable "zone" which is defined in the node.yaml file

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

Stats

Asked: 2014-10-01 06:16:50 -0500

Seen: 403 times

Last updated: Oct 02 '14