0

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".

Red Cricket
  • 9,762
  • 21
  • 81
  • 166

1 Answers1

1

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.

Felix Frank
  • 8,125
  • 1
  • 23
  • 30
  • Yes you are 2nd person to suggest that. I am confused though. Where do I create my /etc/facter/facts.d files, on the puppet master or on the node? Do you think setting the FACTER_pod_prefix env var would work if I put a file /etc/sysconfig/pe-puppet on the node at set env var in that file? – Red Cricket Jul 21 '15 at 18:22
  • Hi Felix, I updated my question with my facts.d attempt. Could you please take a look :) – Red Cricket Jul 21 '15 at 20:18
  • Static fact values can be put in a `facts.d` directory in [any module](https://docs.puppetlabs.com/facter/2.4/custom_facts.html#fact-locations). If you need things to be more dynamic, you will have to manage the files using plain old `file` resources like everything else. – Felix Frank Jul 22 '15 at 09:44