Ask Your Question
0

More hiera examples

asked 2016-03-07 11:26:00 -0600

nobody gravatar image

updated 2016-03-14 05:36:46 -0600

Hi all! I'm use puppet 4.* on Centos 7 and i want to use hiera with it all. Suppose i have 1 puppet master host and 1 node test1. On master i have:

#/etc/puppetlabs/code/hiera.yaml
---
:backends:
 - yaml
 - json
:yaml:
 :datadir: "/etc/puppetlabs/code/hiera/%{::environment}"
:json:
 :datadir: "/etc/puppetlabs/code/hiera/%{::environment}"
:hierarchy:
 - "nodes/%{::fqdn}"
 - "common"

# /etc/puppetlabs/code/hiera/production/nodes/test1.yaml
---
her::parameter_one: "This node is special, so we're overriding the common configuration that the other nodes use."
classes:
  - her

#/etc/puppetlabs/code/environments/production/manifests/classes/her/her.pp 
class her ($parameter_one = "default text") {
  file {'/tmp/her':
      ensure  => file,
      content => $parameter_one,
    }
}

And on test1 i run "puppet agent --debug --no-daemonize --onetime"

Question: How i can run /etc/puppetlabs/code/environments/production/manifests/classes/her/her.pp with "non default" parameters with hiera?

Some server info:

# uname -a
Linux pm2-chel1.is74.ru 3.10.0-327.10.1.el7.x86_64 #1 SMP Tue Feb 16 17:03:50 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
# hiera --version
1.3.4
# puppet master --version
4.3.2
# rpm -qa | grep hiera
hiera-1.3.4-5.el7.noarch
# rpm -qa | grep pupp
puppetlabs-release-pc1-1.0.0-1.el7.noarch
puppetdb-termini-3.2.4-1.el7.noarch
puppet-agent-1.3.5-1.el7.x86_64
puppetdb-3.2.4-1.el7.noarch
puppetserver-2.2.1-1.el7.noarch
# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-03-07 23:25:57 -0600

updated 2016-03-11 05:58:58 -0600

It looks like you've used the %{::fqdn} fact in your Hiera hierarchy while 'test1' appears to be the value for %{::hostname} rather than %{::fqdn}.

Testing your config (I removed the JSON backend to keep it simple):

[root@centos-72-x64 ~]# cat /etc/puppetlabs/code/hiera.yaml
---
:backends:
 - yaml
:yaml:
 :datadir: "/etc/puppetlabs/code/hiera/%{::environment}"
:hierarchy:
 - "nodes/%{::hostname}"
 - "common"

And

[root@centos-72-x64 ~]# cat /etc/puppetlabs/code/hiera/production/nodes/test1.yaml 
---
her::parameter_one: "This node is special, so we're overriding the common configuration that the other nodes use."

Then using the hiera command line:

[root@centos-72-x64 ~]# hiera -d -c /etc/puppetlabs/code/hiera.yaml her::parameter_one ::hostname=test1 ::environment=production
DEBUG: 2016-03-11 11:54:04 +0000: Hiera YAML backend starting
DEBUG: 2016-03-11 11:54:04 +0000: Looking up her::parameter_one in YAML backend
DEBUG: 2016-03-11 11:54:04 +0000: Looking for data source nodes/test1
DEBUG: 2016-03-11 11:54:04 +0000: Found her::parameter_one in nodes/test1
This node is special, so we're overriding the common configuration that the other nodes use.

So if you're still not able to find this key in Hiera:

  • Is your hostname really set to "test1"?
  • Is your environment really "production"?
edit flag offensive delete link more

Comments

Hi Alex! I change "nodes/%{::fqdn}" to "nodes/%{::hostname}" but it has no effect. Any ideas?

nobody gravatar imagenobody ( 2016-03-11 04:41:24 -0600 )edit

Thanks for update, Alex! I answered below, if you do not mind...

nobody gravatar imagenobody ( 2016-03-11 06:22:25 -0600 )edit
1

answered 2016-03-11 06:21:01 -0600

nobody gravatar image

updated 2016-03-11 08:28:12 -0600

Alex, yes, all correct and test ok:

# hiera -d -c /etc/puppetlabs/code/hiera.yaml her::parameter_one ::hostname=test1 ::environment=production
DEBUG: 2016-03-11 17:03:40 +0500: Hiera YAML backend starting
DEBUG: 2016-03-11 17:03:40 +0500: Looking up her::parameter_one in YAML backend
DEBUG: 2016-03-11 17:03:40 +0500: Looking for data source nodes/test1
DEBUG: 2016-03-11 17:03:40 +0500: Found her::parameter_one in nodes/test1
This node is special, so we're overriding the common configuration that the other nodes use.

but if i try run puppet agent --debug --no-daemonize --onetime on test1, i'll get an error:

#puppet agent --debug --no-daemonize --onetime
Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find node statement with name 'default' or 'test1.my.domain, test1.my, test1' on node test1.my.domain

Ok, i made /etc/puppetlabs/code/environments/production/manifests/nodes/main.pp :

node 'test1.my.domain' {
#     include her
#     hiera_include('classes')
}

And now command executed without errors, but puppet not create /tmp/her until i include my classes in /etc/puppetlabs/code/environments/production/manifests/nodes/main.pp :

node 'test1.my.domain' {
    hiera_include('classes')
}

in this case, puppet create /tmp/her with default text . Anyway parameter_one taken not from /etc/puppetlabs/code/hiera/production/nodes/test1.yaml

Why hiera not worked without /etc/puppetlabs/code/environments/production/manifests/nodes/main.pp ?

edit flag offensive delete link more

Comments

This is not the correct filename: #/etc/puppetlabs/code/environments/production/manifests/classes/her/her.pp Neither should you use a nodes directory. Have you done the Quest to Learn Puppet exercises?

Alex Harvey gravatar imageAlex Harvey ( 2016-03-11 10:19:28 -0600 )edit

Alex, not yet, but i'll do. I'd deleted /etc/puppetlabs/code/environments/production/manifests/nodes and moved her.pp to /etc/puppetlabs/code/environments/production/manifests/ but it still has no effect. No errors on test1 and no /tmp/her ...

nobody gravatar imagenobody ( 2016-03-11 11:07:20 -0600 )edit

The file her.pp needs to be in $modulepath/her/manifests/init.pp and you can see $modulepath by running puppet master --configprint modulepath.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-11 21:48:46 -0600 )edit

Hmm. use her.pp as module - is required condition for hiera? Now, without hiera, if i want execute manifest or class, i just added her.pp in /etc/puppetlabs/code/environments/production/manifests/ and include it to /etc/puppetlabs/code/environments/production/manifests/nodes/main.pp as i show earl.

nobody gravatar imagenobody ( 2016-03-12 01:01:38 -0600 )edit
1

Yes, you need your class to correctly use Puppet's Automatic Parameter Lookup feature, otherwise it won't make a call to Hiera. You should google that.

Alex Harvey gravatar imageAlex Harvey ( 2016-03-12 01:25:29 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-03-07 11:26:00 -0600

Seen: 569 times

Last updated: Mar 14 '16