Ask Your Question
1

Custom facts in hiera hierachy not working in CentOS 7

asked 2016-10-06 23:01:54 -0500

Noodles gravatar image

I'm trying to debug a problem where the custom facts from a node are not being used correctly when looking for hiera data. This is my hiera.yaml file:

---
:backends:
  - eyaml
  - yaml
:hierarchy:
  - "nodes/%{::trusted.certname}"
  - "role/%{::instance_role}"
  - "environments/%{::environment}"
  - certs
  - 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:

When I use this with a CentOS 6 node (vagrant box) and /opt/puppetlabs/facter/facts.d/instance_role.txt is set to:

instance_role=web

This works fine. However with the same setup on CentOS 7 (vagrant box) it gives:

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find data item haproxy::listen in any Hiera data file and no default supplied at /etc/puppetlabs/code/environments/dev/site/profile/manifests/haproxy.pp:41:40 on node vagrant.example.com

If I change "role/%{::instance_role}" to "role/web" in hiera.yaml, then that works fine, but it doesn't look like puppet is passing on the custom fact on CentOS 7.

Using puppet 4.7.0, hiera 3.2.1, facter 3.4.1

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-10-06 23:21:42 -0500

Noodles gravatar image

updated 2016-10-09 17:10:21 -0500

So the solution was to move the custom fact to /etc/puppetlabs/facter/facts.d/instance_role.txt

There was also an issue with new line characters (vagrant box was being created on a Windows machine). Once the instance_role.txt was updated to a unix new line characters then it worked as expected.

edit flag offensive delete link more
0

answered 2016-10-07 02:52:08 -0500

lupin gravatar image

You either make that into executable fact, ie instancerole.sh that will output a key=value pair. Or create a structured one using yaml, ie. instacerole.yaml with instance_role: web content.

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: 2016-10-06 23:01:54 -0500

Seen: 74 times

Last updated: Oct 09 '16