Andreas Paul
2012-Apr-30 13:52 UTC
[Puppet Users] querying hiera data without providing host/scope
Hello there,
I need to access the following hiera data in a script:
$ hiera -c /etc/puppet/hiera.yaml tomcats environment=development
line=intra3
["tc7_test1", "tc7_test8"]
or
$ hiera -c /etc/puppet/hiera.yaml apache_port environment=development
line=intra3 name=tc7_test1
81
The example on https://github.com/puppetlabs/hiera uses facts of a specific
hosts.
I don''t want to specify and load each YAML file for each host, because
the
hosts are already defined for a specific line and stage environment:
$ hiera -c /etc/puppet/hiera.yaml hosts environment=development line=intra3
["serverA.domain.tld", "serverB.domain.tld"]
But I can''t get the hiera.lookup to work without providing a scope with
the
facts of a specific host.
I know that I could just call hiera and parse the output, but I thought I
better ask before doing that.
Maybe I''m even using environment and stage specific hiera data the
wrong
way.
Here is my current hiera config:
$ cat /etc/puppet/hiera.yaml
:hierarchy:
- %{environment}/%{line}/%{name}
- %{environment}/%{line}
- %{environment}
:backends:
- yaml
:yaml:
:datadir:
''/etc/puppet/environments/%{environment}/hieradata''
:puppet:
:datasource: data
$ hiera -c /etc/puppet/hiera.yaml apache_port environment=development
line=intra3
80
$ hiera -c /etc/puppet/hiera.yaml apache_port environment=development
line=intra3 name=tc7_test1
81
$ hiera -c /etc/puppet/hiera.yaml apache_port environment=development
line=intra3 name=tc7_test8
80
$ cat /etc/puppet/environments/development/hieradata/development.yaml
---
# default values for this stage
apache_port: ''80''
$ cat /etc/puppet/environments/development/hieradata/development/intra3.yaml
---
# line specific values
hosts: - ''serverA.domain.tld''
- ''serverB.domain.tld''
tomcats: - ''tc7_test1''
- ''tc7_test8''
$ cat
/etc/puppet/environments/development/hieradata/development/intra3/tc7_test1.yaml
---
# tc7_test1 specific values
apache_port: 81
Thanks in advance!
--
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/-/wgIUzVFoXUsJ.
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.
R.I.Pienaar
2012-Apr-30 15:32 UTC
Re: [Puppet Users] querying hiera data without providing host/scope
----- Original Message -----> From: "Andreas Paul" <xorpaul@googlemail.com> > To: puppet-users@googlegroups.com > Sent: Monday, April 30, 2012 2:52:00 PM > Subject: [Puppet Users] querying hiera data without providing host/scope > > Hello there, > > I need to access the following hiera data in a script: > $ hiera -c /etc/puppet/hiera.yaml tomcats environment=development > line=intra3 > ["tc7_test1", "tc7_test8"] > or > $ hiera -c /etc/puppet/hiera.yaml apache_port environment=development > line=intra3 name=tc7_test1 > 81 > > The example on https://github.com/puppetlabs/hiera uses facts of a > specific hosts. > I don''t want to specify and load each YAML file for each host, > because the hosts are already defined for a specific line and stage > environment: > $ hiera -c /etc/puppet/hiera.yaml hosts environment=development > line=intra3 > ["serverA.domain.tld", "serverB.domain.tld"] > > But I can''t get the hiera.lookup to work without providing a scope > with the facts of a specific host.In this case the scope is just a hash so the cli command: $ hiera -c /etc/puppet/hiera.yaml hosts environment=development line=intra3 translates to: hiera.lookup("hosts", nil, {"environment" => "development", "line" => "intra3"}) -- 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.
Andreas Paul
2012-May-02 08:36 UTC
Re: [Puppet Users] querying hiera data without providing host/scope
Ah, exactly what I needed! Thanks! On Monday, April 30, 2012 5:32:26 PM UTC+2, R.I. Pienaar wrote:> > > > ----- Original Message ----- > > From: "Andreas Paul" <xorpaul@googlemail.com> > > To: puppet-users@googlegroups.com > > Sent: Monday, April 30, 2012 2:52:00 PM > > Subject: [Puppet Users] querying hiera data without providing host/scope > > > > Hello there, > > > > I need to access the following hiera data in a script: > > $ hiera -c /etc/puppet/hiera.yaml tomcats environment=development > > line=intra3 > > ["tc7_test1", "tc7_test8"] > > or > > $ hiera -c /etc/puppet/hiera.yaml apache_port environment=development > > line=intra3 name=tc7_test1 > > 81 > > > > The example on https://github.com/puppetlabs/hiera uses facts of a > > specific hosts. > > I don''t want to specify and load each YAML file for each host, > > because the hosts are already defined for a specific line and stage > > environment: > > $ hiera -c /etc/puppet/hiera.yaml hosts environment=development > > line=intra3 > > ["serverA.domain.tld", "serverB.domain.tld"] > > > > But I can''t get the hiera.lookup to work without providing a scope > > with the facts of a specific host. > > In this case the scope is just a hash so the cli command: > > $ hiera -c /etc/puppet/hiera.yaml hosts environment=development > line=intra3 > > translates to: > > hiera.lookup("hosts", nil, {"environment" => "development", "line" => > "intra3"}) > >-- 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/-/zOEtVhTtflgJ. 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.