[Puppet Users] Getting data out of hiera?

44 views
Skip to first unread message

Russell Cecala

unread,
Jul 21, 2015, 5:48:43 AM7/21/15
to puppet-users
Hi,

I use to keep all my class parameters in the default hiera data file, /var/lib/hiera/defaults.yaml, but now I need to maintain another set of nodes that would need to use different values for the class parameters in the defaults.yaml.

I figured, no bug deal, just add the FACTER_something_or_other environment variable to all my nodes and set the value to particular node_set.  Use this env. var in my :hierarchy: section of my hiera.yaml.  But it appears it is not really that easy.

I posted a detailed question on ask puppet but haven't gotten any responses yet.
Could someone please take a look at my question?  I am stumped.


If you prefer, I also posted on stackover flow here


Thanks :)


Thomas Müller

unread,
Jul 21, 2015, 7:22:27 AM7/21/15
to puppet...@googlegroups.com
you need to adjust the hiera hierarchy. To adjust it you need a  top scope variable (e.g. "pod_prefix") (https://docs.puppetlabs.com/puppet/latest/reference/lang_scope.html#top-scope 
)  to be used in hiera.yaml configuration file. 

you could also make a custom fact (https://docs.puppetlabs.com/facter/2.4/custom_facts.html) in a module or a facter-dot-d fact (https://puppetlabs.com/blog/module-of-the-week-puppetlabsstdlib-puppetlabs-standard-library-part-3)

you could also use an hiera based ENC like https://github.com/Zetten/puppet-hiera-enc to  define the value in hiera.

- Thomas

Russell Cecala

unread,
Jul 21, 2015, 5:17:35 PM7/21/15
to puppet-users
I thought I was doing those things.  I set up a FACTER_ env var on one of my nodes to test like so ...

[root@vii-osc4-mgmt-001 ~]# cat /etc/profile.d/POD_prefix.sh 
export FACTER_pod_prefix=vii-osc4
I rebooted the node, vii-osc4-mgmt-001, and checked that env. var is being set (maybe it's not)

[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
So I believe node vii-osc4-mgmt-001 should be reporting the fact pod_prefix to the puppet master.

Then on my puppet master I adjusted the hiera hierarchy by changing my hiera.yaml to this ...

# 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:

# ls -l /var/lib/hiera/svl-osc4.yaml 

-rw-r--r--. 1 root root 49317 Jul 20 15:44 /var/lib/hiera/svl-osc4.yaml

And then I restarted pe-httpd like so ...

# systemctl restart pe-httpd

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/402bde62-1703-4e31-9f9b-35a0edbe34a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Müller

unread,
Jul 21, 2015, 5:35:29 PM7/21/15
to puppet...@googlegroups.com
Systemd services do not have access the normal environment variables that are present in yor shell.

Russell Cecala

unread,
Jul 21, 2015, 6:03:25 PM7/21/15
to puppet-users
I am probably confused when it comes RHEL7. But systemd comes into play here only when I restart my puppet master with "# systemctl restart pe-httpd" right?  I thought I had confirmed that fact pod_prefix is getting set on the node when I execute:

[root@vii-osc4-mgmt-001 ~]# facter pod_prefix
vii-osc4
Are you saying that my test is no good because it is using the environment from the shell?  That sounds like that could be the problem then.  How should I be setting the FACTER_pod_prefix on RHEL7?

On Tue, Jul 21, 2015 at 10:35 AM, Thomas Müller <tho...@chaschperli.ch> wrote:
Systemd services do not have access the normal environment variables that are present in yor shell.
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Russell Cecala

unread,
Jul 21, 2015, 6:32:00 PM7/21/15
to puppet-users
ah you mentioned it already ... fact.d

Thomas Müller

unread,
Jul 21, 2015, 6:33:50 PM7/21/15
to Puppet Users



Are you saying that my test is no good because it is using the environment from the shell?  
yes systemd does not send provide /etc/profile.d environment to its services.

 just don't use FACTER_ env variables. Use facter-dot-d or a custom fact in a puppet module.



- Thomas

Russell Cecala

unread,
Jul 21, 2015, 6:57:48 PM7/21/15
to puppet-users
Gotcha! Thanks

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Russell Cecala

unread,
Jul 21, 2015, 8:10:34 PM7/21/15
to puppet-users
OK I tried looking into the facter-dot-d way of setting a custom fact, but it does not seem suitable for what I am trying to do.
I want some nodes to report the fact pod_prefix as 'vii-osc4' and I will want other nodes to report pod_prefix as 'ix-xyz' so that my hiera.yaml hierachy of ...

root@svl-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:

Will allow nodes with pod_prefix of vii-osc4 to get their class parameters from the /var/lib/hiera/vii-osc4.yaml file while node that have pod_prefix set to 'ix-xyz' will get their class parameters from from /var/lib/hiera/ix-xyz.yaml  ... I do not see how putting this file ...

# pwd

/etc/facter/facts.d

# cat pod_prefix.txt 

pod_prefix=vii-osc4

... on my puppet master will achieve this.

Russell Cecala

unread,
Jul 21, 2015, 9:06:32 PM7/21/15
to puppet-users
Doh! The /etc/facter/facts.d/pod_prefix.txt file goes on the nodes NOT the puppet master.  And it works!
Reply all
Reply to author
Forward
0 new messages