Alexandru Dragoescu
2013-Mar-13 15:26 UTC
[Puppet Users] get a hash from multiple levels(with the same keys but different values) with hiera
Hello, I have this configuration: File: comon.yaml SSH: ConfigFolder: "/etc/ssh/" sshd_config: Protocol: "1,2" SyslogFacility: "AUTHPRIV" *PermitRootLogin*: "no" PasswordAuthentication: "yes" ChallengeResponseAuthentication: "no" GSSAPIAuthentication: "yes" GSSAPICleanupCredentials: "yes" UsePAM: "yes" *ClientAliveInterval*: "100" File test_env.yaml [same keys as in comon.yaml but with different values] : SSH sshd_config: *PermitRootLogin*: "yes" *ClientAliveInterval*: "80" File hiera.yaml: --- :backend: - yaml :hierarchy: - %{environment} - comon :yaml: # datadir is empty here, so hiera uses its defaults: # - /var/lib/hiera on *nix # - %CommonAppData%\PuppetLabs\hiera\var on Windows # When specifying a datadir, make sure the directory exists. :datadir: /etc/puppet/hieradata In puppet code: $ssh_data = hiera_hash(''SSH'') $sshd_config = $ssh_data(''sshd_config'') If a node has %{environment} == test_env I want to retrieve a hash (in sshd_config) like: Protocol: "1,2" SyslogFacility: "AUTHPRIV" * PermitRootLogin: "yes"* PasswordAuthentication: "yes" ChallengeResponseAuthentication: "no" GSSAPIAuthentication: "yes" GSSAPICleanupCredentials: "yes" UsePAM: "yes" * ClientAliveInterval: "80"* if environment != test_env then I want to retrieve : Protocol: "1,2" SyslogFacility: "AUTHPRIV" *PermitRootLogin: "no"* PasswordAuthentication: "yes" ChallengeResponseAuthentication: "no" GSSAPIAuthentication: "yes" GSSAPICleanupCredentials: "yes" UsePAM: "yes" *ClientAliveInterval: "100"* In my setup for the first care i get (it reads only test_env.yaml - that is not what I want): *PermitRootLogin*: "yes" *ClientAliveInterval*: "80" and for the second (reads only comon.yaml - is ok) : Protocol: "1,2" SyslogFacility: "AUTHPRIV" *PermitRootLogin*: "no" PasswordAuthentication: "yes" ChallengeResponseAuthentication: "no" GSSAPIAuthentication: "yes" GSSAPICleanupCredentials: "yes" UsePAM: "yes" *ClientAliveInterval*: "100" Is this possible with my Hiera definition? Thank you, Alex -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Ellison Marks
2013-Mar-13 17:49 UTC
[Puppet Users] Re: get a hash from multiple levels(with the same keys but different values) with hiera
the hiera() call bails out the first time it finds an answer. Assuming you''re calling something like hiera(''sshd_config''), you''re getting that first answer and nothing else. You need to replace the hiera() call with hiera_hash(), which will merge a hash at all levels of the hierarchy, preferring more specific answers. On Wednesday, March 13, 2013 8:26:58 AM UTC-7, Alexandru Dragoescu wrote:> > Hello, > > I have this configuration: > > File: comon.yaml > > SSH: > ConfigFolder: "/etc/ssh/" > sshd_config: > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > *PermitRootLogin*: "no" > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > *ClientAliveInterval*: "100" > > File test_env.yaml [same keys as in comon.yaml but with different values] : > > SSH > sshd_config: > *PermitRootLogin*: "yes" > *ClientAliveInterval*: "80" > > > File hiera.yaml: > > --- > :backend: > - yaml > :hierarchy: > - %{environment} > - comon > > :yaml: > # datadir is empty here, so hiera uses its defaults: > # - /var/lib/hiera on *nix > # - %CommonAppData%\PuppetLabs\hiera\var on Windows > # When specifying a datadir, make sure the directory exists. > :datadir: /etc/puppet/hieradata > > In puppet code: > $ssh_data = hiera_hash(''SSH'') > $sshd_config = $ssh_data(''sshd_config'') > > > If a node has %{environment} == test_env I want to retrieve a hash > (in sshd_config) like: > > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > * PermitRootLogin: "yes"* > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > * ClientAliveInterval: "80"* > > if environment != test_env then I want to retrieve : > > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > *PermitRootLogin: "no"* > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > *ClientAliveInterval: "100"* > > > > In my setup for the first care i get (it reads only test_env.yaml - that > is not what I want): > *PermitRootLogin*: "yes" > *ClientAliveInterval*: "80" > > and for the second (reads only comon.yaml - is ok) : > > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > *PermitRootLogin*: "no" > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > *ClientAliveInterval*: "100" > > Is this possible with my Hiera definition? > > > Thank you, > Alex > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Erik Dalén
2013-Mar-13 23:17 UTC
Re: [Puppet Users] get a hash from multiple levels(with the same keys but different values) with hiera
The reason it doesn''t work is that hiera_hash() only does a shallow merge, not a deep merge of the hashes within the hash. There should be support for deep merging in hiera 1.2.0-rc1 though: http://projects.puppetlabs.com/issues/16107 On 13 March 2013 16:26, Alexandru Dragoescu <dragoescu.alexandru@gmail.com>wrote:> Hello, > > I have this configuration: > > File: comon.yaml > > SSH: > ConfigFolder: "/etc/ssh/" > sshd_config: > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > *PermitRootLogin*: "no" > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > *ClientAliveInterval*: "100" > > File test_env.yaml [same keys as in comon.yaml but with different values] : > > SSH > sshd_config: > *PermitRootLogin*: "yes" > *ClientAliveInterval*: "80" > > > File hiera.yaml: > > --- > :backend: > - yaml > :hierarchy: > - %{environment} > - comon > > :yaml: > # datadir is empty here, so hiera uses its defaults: > # - /var/lib/hiera on *nix > # - %CommonAppData%\PuppetLabs\hiera\var on Windows > # When specifying a datadir, make sure the directory exists. > :datadir: /etc/puppet/hieradata > > In puppet code: > $ssh_data = hiera_hash(''SSH'') > $sshd_config = $ssh_data(''sshd_config'') > > > If a node has %{environment} == test_env I want to retrieve a hash > (in sshd_config) like: > > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > * PermitRootLogin: "yes"* > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > * ClientAliveInterval: "80"* > > if environment != test_env then I want to retrieve : > > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > *PermitRootLogin: "no"* > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > *ClientAliveInterval: "100"* > > > > In my setup for the first care i get (it reads only test_env.yaml - that > is not what I want): > *PermitRootLogin*: "yes" > *ClientAliveInterval*: "80" > > and for the second (reads only comon.yaml - is ok) : > > Protocol: "1,2" > SyslogFacility: "AUTHPRIV" > *PermitRootLogin*: "no" > PasswordAuthentication: "yes" > ChallengeResponseAuthentication: "no" > GSSAPIAuthentication: "yes" > GSSAPICleanupCredentials: "yes" > UsePAM: "yes" > *ClientAliveInterval*: "100" > > Is this possible with my Hiera definition? > > > Thank you, > Alex > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to puppet-users+unsubscribe@googlegroups.com. > To post to this group, send email to puppet-users@googlegroups.com. > Visit this group at http://groups.google.com/group/puppet-users?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- Erik Dalén -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.