Puppet with Hiera - Custom variables

112 views
Skip to first unread message

Stephen

unread,
May 24, 2017, 10:20:56 AM5/24/17
to Puppet Users
Hello,

At the moment I do not use Hiera to store any config at all, but I want to.

Currently, I can use the variable "$mysettings::config::envtype" in my classes, as long as I put 'require mysettings::config' at the head of those classes.

In my environment, I use this variable to hold "PROD", "DEV", "PERFTEST", "QA", etc (It derives this from IP subnet).


I have this in my hiera.yaml file, which successfully pulls the data from, for example, the os/RedHat.yaml file when needed.
  - name: "OS defaults"
    path: "os/%{facts.os.family}.yaml"
   

   
How do I use my variable above in the same way? I've tried the below, and a number of other syntaxes, and can't get it working. ie. I want to retrieve config from the envtype/DEV.yaml file, but it's not returning anything.
  - name: "Envtype data"
    path: "envtype/%{'mysettings::config::envtype'}.yaml"
   

Apologies if this is explained in documentation, I have gone over it and it's just not clicking for me. Should I be doing it this way, should I be using custom facts, should I be doing something else?

I'm on Puppet PE v2017.1.0.

Thanks for any help.

Arnau

unread,
May 24, 2017, 10:51:38 AM5/24/17
to puppet...@googlegroups.com
Hi,

I don't know if there's another (or better) way, but I use a custom fact for the environment. Then you can tell hiera to use this new fact in the hierarchy tree:

As an example:
node:

/etc/facter/facts.d/local.yaml
---
env: "prod"

puppet server:
/etc/puppet/hiera.yaml

---
:backends:
  - yaml
  - eyaml
:hierarchy:
  - "%{environment}/hieradb/%{::env}/cert/%{::clientcert}"


Notice that %{environment} refers to puppet environemnt. (In my case those are the git branches that I create).


HTH,
Arnau


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/c569bc63-69b5-481c-8f38-7e3388ea49a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stephen

unread,
May 25, 2017, 6:15:43 AM5/25/17
to Puppet Users

Thank you very much for this. I have successfully tested it!

I perfer the idea of Puppet 'knowing' which yaml file to use by way of a passed variable, rather than having to read from disk for it (and if there is a way to do this, I'd like to hear it).

But your solution works and it's not complicated, so thank you :)

Kind regards,
Stephen
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.

Arnau

unread,
May 25, 2017, 7:53:41 AM5/25/17
to puppet...@googlegroups.com
Hi,

the typical scenario for running nodes in differnet environments is to use r10k.

git + r10k . It's a well known combo that works perefctly.

Best,
Arnau


To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/48209bb7-1c96-4a51-abc1-7ca7ccc1bb95%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages