Search code examples
hierapuppet-enterprise

How come data is not coming from my hiera yaml file?


I am using Puppet Enterprise 3.7.2 and on one of my nodes I create the file:

[root@vii-osc4-mgmt-001 ~]# cat /etc/profile.d/POD_prefix.sh 
export FACTER_pod_prefix=vii-osc4

Then I rebooted that node and logged back in and verified that the FACTER_pod_prefix gets set and facter pod_prefix outputs the expected value.

[root@vii-osc4-mgmt-001 ~]# env | grep FACTER_pod_prefix
FACTER_pod_prefix=vii-osc4
[root@vii-osc4-mgmt-001 ~]# facter pod_prefix
vii-osc4

On my PE 3.7 Puppet master I created the file /var/lib/hiera/vii-osc4.yaml. I created the /var/lib/hiera/vii-osc4.yaml from the /var/lib/hiera/defaults.yaml file that I had been using like so:

# cp /var/lib/hiera/defaults.yaml /var/lib/hiera/vii-osc4.yaml

This file has a bunch of class parameter values. For example there is this line in the file:

controller_vip_name: vii-osc4.example.com 

Then I changed my hiera.yaml file to look like this:

[root@osc4-ppt-001 ~]# cat /etc/puppetlabs/puppet/hiera.yaml
---
:backends:
  - yaml
:hierarchy:
  - "%{pod_prefix}"
  - defaults
  - "%{clientcert}"
  - "%{environment}"
  - global

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:

Then I restarted my pe-httpd service like so (RHEL7):

# systemctl restart pe-httpd

Then I make a small change to the /var/lib/hiera/vii-osc4.yaml for example I change the line ...

controller_vip_name: vii-osc4.example.com

... to ...

controller_vip_name: VII-osc4.example.com

But when I run puppet agent -t --noop on my node, vii-osc4-mgmt-001, I do not see the change that I expected to see. If I make the change in the /var/lib/hiera/defaults.yaml and then run puppet agent -t --noop on my node I do see the expected changes. What am I doing wrong here?

UPDATE: using /etc/facter/facts.d method of setting custom facts.

I looked into using /etc/facter/facts.d for what I am trying to do. What I am trying to do is set a custom fact "pod_prefix". I want to use this fact in my hiera.yaml like so ...

---
:backends:
  - yaml
:hierarchy:
  - "%{::pod_prefix}"
  - defaults
  - "%{clientcert}"
  - "%{environment}"
  - global

:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
  :datadir:

... so that nodes that have pod_prefix set to vii-osc4 will obtain their class parameters from the file /var/lib/hiera/vii-osc4/yaml and host that pod_prefix set to ix-xyz will get their class params from /var/lib/hiera/ix-xyz.yaml. I do not see how creating the file /etc/facter/facts.d/pod_prefix.txt on my puppet master that contains something like this ...

# cat pod_prefix.txt 
pod_prefix=vii-osc4

... could possibly be a solution to my problem. I guess I must be misunderstanding something here. Can someone help?

UPDATE 2.

The /etc/facter/facts.d/pod_prefix.txt file goes on my nodes. I think my biggest problem is that just execute systemctl restart pe-httpd was not sufficient and things didn't start working until I did a full reboot of my puppet master. I need to go look at the docs and figure out what is the correct way to restart the "puppet master".


Solution

  • The very approach of managing custom facts through environment variables is quite brittle. In this case, I suspect it does not work because you changed the environment of login shells via /etc/profile.d. System services don't run in such shells, though.

    A clean approach would be to define your fact value in /etc/facter/facts.d instead.