Hiera - how to include all files inside a directory

278 views
Skip to first unread message

Juan Moreno

unread,
Jul 24, 2014, 8:27:58 AM7/24/14
to puppet...@googlegroups.com
Hi,

I would like to know if exists the possibility to include all the yaml files of a directory in hiera.

The hiera config looks like:

:hierarchy:
  - %{hostname}
  - secrets
  - customers/*

:backends:
  - yaml
:yaml:
  :datadir: '/etc/puppet/data'


Cheers,
Juan Moreno

Pete Brown

unread,
Jul 24, 2014, 7:03:00 PM7/24/14
to puppet-users
I don't believe that is possible.
You will probably need to collate all the files in customers/ into one file.

I am going to hazard a guess that you have data relating to your
customers in that directory.
If the data in those files is specific to each customer and each of
your nodes had only one customer on it you could set a custom fact and
use that to as a lookup in your hiera tree.
Does that make sense?
> --
> 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/e069d96d-7ec4-4bb2-bd68-76143609596b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

John Warburton

unread,
Jul 24, 2014, 7:14:30 PM7/24/14
to puppet-users
I presume you just want the information for the one customer, and not all customers?

If the first, I assume you set the customer name, and you just dump the information in a file named after the customer. If you want all customers, dump it all in one common file.

Whilst, we're still using extlookup, the idea is the same (and we set the client name in our node classifier). We have client information based on location or just general, with global overrides in "common"

$extlookup_precedence = ["host_%{fqdn}",
                         "%{client}.location_%{location}",
                         "%{client}",
                         "location_%{location}",
                         "common"]

John


--
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/e069d96d-7ec4-4bb2-bd68-76143609596b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
John Warburton
Ph: 0417 299 600
Email: jwarb...@gmail.com

Juan Moreno

unread,
Jul 25, 2014, 3:15:41 AM7/25/14
to puppet...@googlegroups.com
Thanks Pete and John.

Now we've got a puppet module that use a unique file in hiera, inside this file (associative hash), we've all the customers and the specific data from each one. This allow us to create Vhosts in Apache, creates specific tomcat webapps, set quotas in distributed file systems...

All the Apaches nodes has all vhosts from the customers, and the same for the tomcat and distributed filesystems.

The idea is to split this file in a file per customer, manage and creates one file per customer is easier than one big file with all the customers. And merge this set of files in execution time with a hiera merge.

current:

$ cat data/customers.yaml
---
### customers

customers
:
 
  client1
:
    code
: 'c1'
    name
: 'client1'
    pre
: 'yes'
    pro
: 'yes'
    dom_pro
: 'www.client1.com'
    dom_pre
: 'www.pre.client1.com'
    http_pro
: 'no'
    https_pro
: 'no'
    http_pre
: 'no'
    https_pre
: 'no'
    descripcion
: 'Description Client 1'
    cuota
: '2.0TB'

  client2:
    code
: 'c2'
    name
: 'client2'
    pre
: 'yes'
    pro
: 'yes'
    dom_pro
: 'www.client2.com'
    dom_pre
: 'www.pre.client2.com'
    http_pro
: 'no'
    https_pro
: 'no'
    http_pre
: 'no'
    https_pre
: 'no'
    descripcion
: 'Description Client 2'
    cuota
: '2.0TB'


later:


$ cat data/client1.yaml
---
### customers

customers
:
 
  client1
:
    code
: 'c1'
    name
: 'client1'
    pre
: 'yes'
    pro
: 'yes'
    dom_pro
: 'www.client1.com'
    dom_pre
: 'www.pre.client1.com'
    http_pro
: 'no'
    https_pro
: 'no'
    http_pre
: 'no'
    https_pre
: 'no'
    descripcion
: 'Description Clie 1'
    cuota
: '2.0TB'

$ cat data/client2.yaml
---
### customers

customers
:
 
 
  client2:
    code
: 'c2'
    name
: 'client2'
    pre
: 'yes'
    pro
: 'yes'
    dom_pro
: 'www.client2.com'
    dom_pre
: 'www.pre.client2.com'
    http_pro
: 'no'
    https_pro
: 'no'
    http_pre
: 'no'
    https_pre
: 'no'
    descripcion
: 'Description Clie 1'
    cuota
: '2.0TB'

Cheers,
Juan Moreno

Juan Moreno

unread,
Aug 1, 2014, 3:30:15 AM8/1/14
to puppet...@googlegroups.com

Here, we have a solution:


Cheers

El jueves, 24 de julio de 2014 14:27:58 UTC+2, Juan Moreno escribió:

Pete Brown

unread,
Aug 11, 2014, 4:53:09 AM8/11/14
to puppet-users
I am glad you found a solution.
That looks pretty handy.
Thanks for the link.
> --
> 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/817813cb-9d9f-4633-aa55-c891875cf253%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages