Josh
2012-Sep-03 15:21 UTC
[Puppet Users] Problem with hiera arrays not obeying the hierachy
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 -- 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-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Josh
2012-Sep-03 15:42 UTC
[Puppet Users] Re: Problem with hiera arrays not obeying the hierachy
...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 -- 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-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Aaron Grewell
2012-Sep-03 16:11 UTC
Re: [Puppet Users] Re: Problem with hiera arrays not obeying the hierachy
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(). On Sep 3, 2012 8:42 AM, "Josh" <josh@chickenmonkey.co.uk> wrote:> ...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 > > -- > 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-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Josh
2012-Sep-04 08:10 UTC
Re: [Puppet Users] Re: Problem with hiera arrays not obeying the hierachy
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 -- 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/-/c3MNQGhVEdYJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Josh
2012-Sep-04 13:11 UTC
Re: [Puppet Users] Re: Problem with hiera arrays not obeying the hierachy
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 -- 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/-/0TImwu3Ae-gJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Wolf Noble
2012-Sep-04 18:26 UTC
Re: [Puppet Users] Problem with hiera arrays not obeying the hierachy
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 <josh@chickenmonkey.co.uk> wrote:> 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 > > -- > 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-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@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. -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.