Problem with hiera arrays not obeying the hierachy

599 views
Skip to first unread message

Josh

unread,
Sep 3, 2012, 11:21:55 AM9/3/12
to puppet...@googlegroups.com
Versions: puppet 2.7.18, hiera 0.3.0

I have encountered a problem that is completely counter intuitive to how I thought hiera was meant to work. I have three levels in my hierarchy in the following order:
- <node>.yaml   (specific to the host)
- <datacentre>.yaml   (we have multiple sites, this is info specific to the site)
- common.yaml   (applies to everything)

I noticed this problem while working round a DNS problem, needless to say I had the following (ip addresses changes to protect the innocent) in the <datacentre>.yaml:

dns_servers:
  - '1.1.1.1'
  - '2.2.2.2'

I wanted a specific host to use different DNS so in the <node>.yaml I added:

dns_servers:
  - '3.3.3.3'

Now, when I do a hiera_array('dns_servers') I would expect that the original array (1.1.1.1 and 2.2.2.2) would be overwritten with a single value (3.3.3.3)...

As it turned out is concatenated the two arrays together, giving me (1.1.1.1 and 2.2.2.2 and 3.3.3.3). Non-plussed I added another entry to the common.yaml (4.4.4.4) and lo and behold it added that in as well giving me  (1.1.1.1 and 2.2.2.2 and 3.3.3.3 and 4.4.4.4).

I really did assume from the documentation that the hierarchy would be obeyed and both <datacentre>.yaml and common.yaml would be ignored ... or have I misunderstood how the system works?

Thanks
Josh 

Josh

unread,
Sep 3, 2012, 11:42:32 AM9/3/12
to puppet...@googlegroups.com
...my hiera.conf since it would probably help. %{datacentre} is a custom fact that is set at build time:

---
:hierarchy:
  - node/%{hostname}
  - common/%{datacentre}
  - common/common
:backends:
  - yaml
  - puppet
:yaml:
  :datadir: '/local/puppet/env/%{environment}/hieradata'
:puppet:
  :datasource: data

Aaron Grewell

unread,
Sep 3, 2012, 12:11:16 PM9/3/12
to puppet...@googlegroups.com

The hiera function works as you described and supports strings, arrays and hashes. The hiera_array and hiera_hash functions build additive arrays and hashes that include the values of all matching variables across the entire hierarchy. For your use case you should use hiera()  instead of hiera_array().

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/7FV-TOufBLcJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Josh

unread,
Sep 4, 2012, 4:10:57 AM9/4/12
to puppet...@googlegroups.com
On Monday, September 3, 2012 5:11:23 PM UTC+1, Aaron Grewell wrote:

The hiera function works as you described and supports strings, arrays and hashes. The hiera_array and hiera_hash functions build additive arrays and hashes that include the values of all matching variables across the entire hierarchy. For your use case you should use hiera()  instead of hiera_array()


Really, thats brilliant cheers. Not only does that fix my problem but I can remove a whole load of weird hacks I had in place merging hases together. I also upgraded to hiera 1.0 to try and fix so all good.

What is the behaviour regarding hash keys? Would a merged hash that ends up with a duplicate key take the value from higher up the hierarchy?

Thanks again,
Josh

Josh

unread,
Sep 4, 2012, 9:11:20 AM9/4/12
to puppet...@googlegroups.com
On Tuesday, September 4, 2012 9:10:57 AM UTC+1, Josh wrote:
What is the behaviour regarding hash keys? Would a merged hash that ends up with a duplicate key take the value from higher up the hierarchy

Have answered my own question. The answer to this is yes (for the benefit of people who come across this post in future)

Josh 

Wolf Noble

unread,
Sep 4, 2012, 2:26:40 PM9/4/12
to <puppet-users@googlegroups.com>
I believe hiera_array() collects and provides an array of all the relevant elements up the entirety of the tree. To collect only the most relevant data just use hiera()



On Sep 3, 2012, at 10:21 AM, Josh <jo...@chickenmonkey.co.uk>
wrote:
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/e-jCVgKPe6AJ.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.


________________________________

This message may contain confidential or privileged information. If you are not the intended recipient, please advise us immediately and delete this message. See http://www.datapipe.com/legal/email_disclaimer/ for further information on confidentiality and the risks of non-secure electronic communication. If you cannot access these links, please notify us by reply message and we will send the contents to you.
Reply all
Reply to author
Forward
0 new messages