2

I'm trying to understand how does Puppet hierarchy works.

My Puppet server's hiera.yaml looks like so:

[root@puppet puppet]# cat hiera.yaml 
:backends: 
  - yaml 
:yaml: 
  :datadir: '/etc/puppet/hieradata/%{::environment}' 
:hierarchy: 
  - fqdns/%{::fqdn} 
  - roles/%{::role} 
  - domains/%{::domain} 
  - common

There are modules which I want all servers to have so I've put them in the common.yaml file and there are role-specific modules which are included in each role.yaml file.

When a server which matches a role in Puppet starts, the modules from the role.yaml file are loaded first. My question is: Once a server is matched with a role... will it stop there? or will it continue in the hierarchy and load the modules under the common.yaml as well?

If not, How can I make sure that this is how it will behave?

Edit #1: Here's an example of one of the role.yaml files:

[root@puppet roles]# cat dataorigin.yaml 
classes:
  - workspace

jdk_enable: true
jdk_ver: 1.6.0_41
component_ver: 1-1-5-17
tomcat_enable: true
debug_mode: true

fstab_params:
  mount1:
    mnt_src:  "isilonnj01.eyedcny.local:/ifs/Peer39/do_share"
    mnt_dest: "/doshare"
    mnt_opts: "tcp,hard,intr,noatime"
    mnt_dest_parent: ""

And the server's site.pp looks like so:

hiera_include("classes", [])
Package {  allow_virtual => false, }
node default {
include stdlib
}

Edit #2: Here's an example of a motd module:

include stdlib
class motd {
    file { "/etc/custom_motd.sh":
    path    => '/etc/custom_motd.sh',
    ensure  => present,
    owner   => "root",
    group   => "root",
    mode    => "775",
    content => template('motd/custom_motd.sh.erb'),
    #require => Class['nagios_client'],
    }

    file_line { 'enable motd':
    ensure  => present,
    line    => '/etc/custom_motd.sh',
    path    => '/etc/profile',
    require  => File['/etc/custom_motd.sh']
    }
}

The motd module is configured in the common.yaml file, and in the role.yaml file there's a module called workspace. How can I tell Puppet to load the motd module from the common.yaml file?

4
  • How are these modules being included? I assume you have a hiera_include, or are you doing something else?
    – Zoredache
    Apr 13, 2015 at 7:42
  • Please check Edit #1
    – Itai Ganot
    Apr 13, 2015 at 7:55
  • @ItaiGanot How can I tell Puppet to lost the motd module from the common.yaml file? Can you rephrase that please? You want Hiera to yield only the first match, not all? You want to selectively ignore one module? I'm not sure.
    – fuero
    Apr 13, 2015 at 8:11
  • I had a typo there, lost = load , sorry
    – Itai Ganot
    Apr 13, 2015 at 8:12

1 Answer 1

2

Hiera is a tool to lookup data. You give it a key name and it walks through its data files and returns the first match (which should be the most specific one) it comes up with, traversing downwards in its hierarchy.

Using it within puppet, you have more options what to do if there is more than one value for a key:

hiera
    Standard priority lookup. Gets the most specific value for a given key. 
    This can retrieve values of any data type (strings, arrays, hashes) 
    from Hiera.
hiera_array
    Uses an array merge lookup. Gets all of the string or array values 
    in the hierarchy for a given key, then flattens them into a single 
    array of unique values.
hiera_hash
    Uses a hash merge lookup. Expects every value in the hierarchy for
    a given key to be a hash, and merges the top-level keys in each 
    hash into a single hash. Note that this does not do a deep-merge 
    in the case of nested structures.

Using hiera as an ENC to load modules works like this (Emphasis added):

Note that the hiera_include function uses an array merge lookup to retrieve the classes array; this means every node will get every class from its hierarchy.

So if you followed the docs and used hiera_include, all classes you specified throughout the hierarchy for a node will be loaded.

In your example, assuming role=dataorigin, and that common.yaml looks like this:

---
classes:
 - a

Your site.pp will cause the modules workspace, stdlib and a to be assigned to the querying node.

5
  • I'm having trouble to see how this answers my question... My question was... Once a role is matched, will it continue loading the modules I specified in the common.yaml as well or will it stop there since there was a match in the roles?
    – Itai Ganot
    Apr 13, 2015 at 7:54
  • You'll have to show us how exactly you use Hiera to load modules. As I mentioned, hiera just looks up data. everything else is up to your manifests.
    – fuero
    Apr 13, 2015 at 7:57
  • Please tell me which info you need and I'll post it
    – Itai Ganot
    Apr 13, 2015 at 8:00
  • @ItaiGanot: I've updated my answer, I hope it's clear enough now :-)
    – fuero
    Apr 13, 2015 at 8:05
  • Thanks, I'll check it now, please check my Edit #2, thanks.
    – Itai Ganot
    Apr 13, 2015 at 8:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .