Ask Your Question
0

hiera doesn't work

asked 2016-06-03 12:47:24 -0500

nobody gravatar image

Hi all! I have puppetmaster 4 + puppetdb 4.1 and i try to use hiera... In puppet master:

puppet nodes # cat /etc/puppetlabs/code/hiera.yaml 
---
:backends:
  - yaml
:yaml:
:datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - "nodes/%{::hostname}"
  - common


puppet nodes # cat /etc/puppetlabs/code/environments/production/hieradata/nodes/puppetdb.yaml 
# /etc/puppetlabs/code/production/hieradata/web01.example.com.yaml
---
ntp::restrict:
 -
ntp::autoupdate: false
ntp::enable: true
ntp::servers:
 - 0.us.pool.ntp.org iburst
 - 1.us.pool.ntp.org iburst
 - 2.us.pool.ntp.org iburst
 - 3.us.pool.ntp.org iburst

Why if i run in puppetdb puppet agent -t

Info: Using configured environment 'production'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for puppetdb
Info: Applying configuration version '1464975833'
Notice: Applied catalog in 0.03 seconds

Nothing happens... Maybe i must do anything else?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-06-03 20:03:52 -0500

DarylW gravatar image

updated 2016-06-03 23:03:07 -0500

You can't entirely drive your configuration from hiera. You need to have a site.pp using a hiera_include('classes') or a node declaring the nodes you wish to run, and hiera will just fill in the values for the parameters of the classes you wish to include.

I would start with the traditional method... Here's the official puppet docs on how to Assign Configuration to nodes

If you want to use hiera as an ENC(External Node Classifier), you can use hierainclude... Here is an example of using hierainclude to load classes into your configuration... assigning-classes-to-nodes-with-hiera-include

Also to clarify... the reason your run 'succeeds' but doesn't do anything is because it is applying an empty catalog, since you haven't actually specified any classes to include.

edit flag offensive delete link more

Comments

Hmm, i think if i use hiera, there is no need to use site.pp , all nodes daclares in /etc/puppetlabs/code/environments/production/hieradata/nodes/ - it's not true? :(

nobody gravatar imagenobody ( 2016-06-03 22:25:58 -0500 )edit

Hiera is just a collection of data. in that file, you are defining the values that hiera will supply when the node name matches the name of your file. If you pair it with a 'classes' array, and you list all the classes you need, via my hiera_include link above, you will get the results you want

DarylW gravatar imageDarylW ( 2016-06-03 23:00:53 -0500 )edit

either way, you still need a site.pp that has the hiera_include('classes') call to actually do the class setup

DarylW gravatar imageDarylW ( 2016-06-03 23:01:15 -0500 )edit

Ok, if i create site.pp with *node puppetdb { hiera_include('classes') }* , then in /etc/puppetlabs/code/environments/production/hieradata/nodes/puppetdb.yaml everything will work?

nobody gravatar imagenobody ( 2016-06-04 00:20:22 -0500 )edit

I ran into a similar problem, puppet master v4. hiera_include('classes') is not finding my classes at all. puppet config print hiera_config gives me /etc/puppetlabs/code/hiera.yaml (not /etc/puppetlabs/code/hiera.yaml what you use). symlinking did not help so far. cmdline hiera give ok values !

sandy gravatar imagesandy ( 2016-07-05 10:11:14 -0500 )edit
0

answered 2016-07-07 07:07:31 -0500

sandy gravatar image

First, about hiera_include('classes'), yes you need that.

Documentation says: The main manifest can be a single file, or a directory containing many files. Here is my working example, using a single, explicit site.pp file:

puppet config print hieraconfig
/etc/puppetlabs/puppet/hiera.yaml # standard, did not change this
... hiera
include('classes')

Make sure you know where you hiera_config is:

puppet config print hiera_config
/etc/puppetlabs/puppet/hiera.yaml # standard, did not change this

Hierarchy:

cat /etc/puppetlabs/puppet/hiera.yaml

:hierarchy:
- hostname/%{hostname}
... some more levels... but left it out for clarity...
- default
:backends:
- yaml

I did NOT set the datadir explicitly, so when running puppet agent -t --environment=development... the /etc/puppetlabs/code/environments/development/hieradata directory is used.

Those 2 files from the hierarchy get evaluated:

/etc/puppetlabs/code/environments/development/hieradata/default.yaml
/etc/puppetlabs/code/environments/development/hieradata/hostname/myhost.yaml

In default.yaml, I assign some classes (my own...)

classes:
- cron
- dns

And they do get applied when running puppet.

Hope it helps.

edit flag offensive delete link more

Comments

Using puppet server 2.4.0, puppetdb 4.1.2 on centos 6.8

sandy gravatar imagesandy ( 2016-07-07 07:09:35 -0500 )edit

sandy, thank you so much, i did it already, and it works fine ^_^

nobody gravatar imagenobody ( 2016-07-12 09:41:18 -0500 )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

2 followers

Stats

Asked: 2016-06-03 12:47:24 -0500

Seen: 456 times

Last updated: Jul 07 '16