Hiera.yaml not picking up the %{environment} variable from the node

523 views
Skip to first unread message

Dennis McCarthy

unread,
Aug 13, 2017, 10:04:47 AM8/13/17
to Puppet Users
Hi,

I'm setting up Puppet 4.0 for the first time and I'm probably missing something. In my hiera.yaml:

---
:backends:
 
- yaml
:hierarchy:
 
- "%{application}"
 
- common


:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /etc/puppetlabs/code/environments/%{environment}/hieradata on *nix
# - %CommonAppData%\PuppetLabs\code\environments\%{environment}\hieradata on Windows
# When specifying a datadir, make sure the directory exists.
 
:datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
#  :datadir: /etc/puppetlabs/code/environments/development/hieradata

With this setting I get this on the node:

root@dc1dapp01:~# facter -p | grep application
application
=> app
root@dc1dapp01
:~#
root@dc1dapp01
:~# puppet agent -t
Info: Using configured environment 'development'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for dc1dweb01.example.com
Info: Applying configuration version '1502632775'
Notice: site.pp
Notice: /Stage[main]/Main/Notify[site.pp ]/message: defined 'message' as 'site.pp '
Notice:  this is the role_basic role
Notice: /Stage[main]/Role_basic/Notify[ this is the role_basic role ]/message: defined 'message' as ' this is the role_basic role '
Notice: Applied catalog in 0.05 seconds

But if i explicitly point to environment development in the Hiera.yaml file, I get the following output (this is the behavior I want):

root@dc1dapp01:~# puppet agent -t
Info: Using configured environment 'development'
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for dc1dweb01.example.com
Info: Applying configuration version '1502632844'
Notice: site.pp
Notice: /Stage[main]/Main/Notify[site.pp ]/message: defined 'message' as 'site.pp '
Notice:  this is the APP1 module
Notice: /Stage[main]/App1/Notify[ this is the APP1 module ]/message: defined 'message' as ' this is the APP1 module '
Notice: Applied catalog in 0.03 seconds

I have a fact for the application that I want to run a specific role/profile for. Can anyone explan what I'm missing please?

Thanks for your help.

Here are some of my other config files:

environment.conf

# Each environment can have an environment.conf file. Its settings will only
# affect its own environment. See docs for more info:
# https://docs.puppetlabs.com/puppet/latest/reference/config_file_environment.html


# Any unspecified settings use default values; some of those defaults are based
# on puppet.conf settings.


# If these settings include relative file paths, they'll be resolved relative to
# this environment's directory.


# Allowed settings and default values:


 modulepath
= ./modules:$basemodulepath
# manifest = (default_manifest from puppet.conf, which defaults to ./manifests)
# config_version = (no script; Puppet will use the time the catalog was compiled)
# environment_timeout = (environment_timeout from puppet.conf, which defaults to 0)
   
# Note: unless you have a specific reason, we recommend only setting
   
# environment_timeout in puppet.conf.

# cat manifests/site.pp


notify
{ 'site.pp ': }
#hiera_include('classes')


  $role
= hiera('classes','role_basic')
  include $role




Mike Sharpton

unread,
Aug 14, 2017, 8:30:11 AM8/14/17
to Puppet Users
Did you just change hiera.yaml?  If so, you must restart puppetserver for changes to take effect.  We do something similar with roles, with this site.pp.  Stolen from Gary and it works well.

node default {
  $role = hiera('role')
  include $role
}


You need to set 'role' somewhere in your hieradata in which the first found in your hierarchy will win.  This is hard to answer well without understanding what you have in your hiera data.  This role needs to be set in your %{application} yaml file.

Not sure how helpful this will be.  

Mike

Dennis McCarthy

unread,
Aug 14, 2017, 8:37:41 AM8/14/17
to Puppet Users
Hi Mike,

Thanks for your reply. I've realised my mistake in that I need to have a separate site.pp per environment. I'm used to just having one but with puppet 4.0 they've had a change around.

And yes I'm implementing the "role" like you are in the relevant .yaml files under hieradata. Thank you Gary and Craig.

Cheer Mike

Reply all
Reply to author
Forward
0 new messages