FAQ
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.

Search Discussions

  • R.I.Pienaar at Apr 30, 2012 at 3:32 pm

    ----- 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 at May 2, 2012 at 8:37 am
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedApr 30, '12 at 1:52p
activeMay 2, '12 at 8:37a
posts3
users2
websitepuppetlabs.com

2 users in discussion

Andreas Paul: 2 posts R.I.Pienaar: 1 post

People

Translate

site design / logo © 2022 Grokbase