Ask Your Question
0

Hiera can't find environment - %{environment} = nil

asked 2015-11-28 18:05:13 -0500

Kint gravatar image

I was having problems getting hiera to find a data source, then by debugging with -d, I realised %{environment} is returning nil.

#hiera -d ntp::enable
DEBUG: 2015-11-28 23:18:50 +0000: Hiera YAML backend starting
DEBUG: 2015-11-28 23:18:50 +0000: Looking up ntp::enable in YAML backend
DEBUG: 2015-11-28 23:18:50 +0000: Looking for data source common
DEBUG: 2015-11-28 23:18:50 +0000: Cannot find datafile /etc/puppetlabs/code/environments//hieradata/common.yaml, skipping

When I pass the environment manually:

# hiera -d ntp::enable environment=production
DEBUG: 2015-11-28 23:18:43 +0000: Hiera YAML backend starting
DEBUG: 2015-11-28 23:18:43 +0000: Looking up ntp::enable in YAML backend
DEBUG: 2015-11-28 23:18:43 +0000: Looking for data source common
DEBUG: 2015-11-28 23:18:43 +0000: Found ntp::enable in common
true

Initially I thought that an unset environment on my nodes was the cause. But then it hit me that when I puppet agent -t on any of my nodes, the first line outputted is Info: Using configured environment 'production'. So it seems the set environment isn't the problem.

To be extra safe, I have set environment = production under [master] in /etc/puppetlabs/puppet/puppet.conf on my puppet master, and I restarted puppet and puppetserver, but alas still hiera returns nil for %{environment}.

Here is my hiera.yaml:

---
:backends:
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - 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:

So I suppose my question is, why does %{environment} = nil?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-11-30 13:03:43 -0500

lavaman gravatar image

Running Hiera manually is fundamentally different from using it via puppet. There are no values provided automatically for any variables (including environment) when running from the command line. Hiera knows nothing of your puppet config when run manually, so changing that won't affect what hiera sees when run manually. You must always provide all relevant variable values on the command line when running hiera manually.

edit flag offensive delete link more

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: 2015-11-28 17:30:33 -0500

Seen: 1,017 times

Last updated: Nov 30 '15