Ask Your Question
0

Why isn't Puppet reading hiera values?

asked 2015-05-21 10:52:21 -0600

qwerty_face gravatar image

updated 2015-05-21 10:54:09 -0600

Hello, this is lengthy due to adding the relevant code. In a nutshell I am using puppet to install some software onto my server (agent) based on [two] compound conditions: firstly, what environment the node is in, and secondly, whether there is a boolean value of true defined for that node in that node's yaml file (since I have configured hiera to lookup key/value pairs firstly from the node's yaml followed by the environment's yaml file (in my case the former takes precedence over the latter)). By default the boolean is false for the environment so a node must have it's own yaml file with a true value for the relevant key being looked up to install the software on the node. It is designed this way so that the software is not installed unless specifically specified for that node. Anyway...

The problem I have is that my server exampleserver is not installing the software I'd expect it to despite having a boolean value of true (for the relevant key) in it's node yaml file. After some playing around I can install the software successfully if I take the hiera parameter out of the equation, but when I insert it - no dice. I'm certain that Puppet and hiera are not "talking" with each other on the PM, but I cannot fathom why.

I'll begin with my node definition which looks like:

node exampleserver {
    include roles::testrole 
}

My testrole recipe in module roles looks like:

class roles::testrole {
    include profiles::linux_profile 
}

Inside my linux_profile recipe in module profiles I have:

class profiles::linux_profile {
    include stdlib::stages
    class { "profiles::config": stage => setup, } 
} 
class profiles::config {

    if ($environment =~ /(dev|DEV)/) and ($install_extra == true) {
        class { somesoftware: }
    } 
}

Boolean variable $install_extra is (supposed to be) passed in by hiera. The dev.yaml file contains:

profiles::config::install_extra: false

Where the node's yaml file exampleserver.yaml (in directory dev) contains:

profiles::config::install_extra: true

And my hiera.yaml file looks like:

-- 
:backends:
  - yaml

:yaml:   
    :datadir: /pupstuff/puppet/environments/%{::environment}/hieradata/

:hierarchy:
  - %{::environment}/%{::hostname}
  - %{::environment}
  - common

Again, the problem I have is that somesoftware module (which installs some software...) is never added to the node's catalogue despite my hiera lookup on the PM returning the correct boolean value that I would expect:

[root@mypuppetmaster puppet]# hiera profiles::config::install_extra ::environment=DEV ::hostname=exampleserver -d -c /etc/puppet/hiera.yaml DEBUG: Thu May 21 11:25:51 +0100 2015: Hiera YAML backend starting DEBUG: Thu May 21 11:25:51 +0100 2015: Looking up profiles::config::install_extra in YAML backend DEBUG: Thu May 21 11:25:51 +0100 2015: Looking for data source DEV/exampleserver DEBUG: Thu May 21 11:25:51 +0100 2015: Found profiles::config::install_extra in DEV/exampleserver true

[root@mypuppetmaster puppet]# hiera profiles::config::install_extra ::environment=DEV -d -c /etc/puppet/hiera.yaml DEBUG: Thu May 21 11:25:58 +0100 2015: Hiera YAML backend starting DEBUG: Thu May 21 11:25:58 +0100 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-21 16:02:01 -0600

Hypnoz gravatar image

You can't just use $install_extra without telling it in some way to use hiera for that variable. You have 2 ways.

1) In the top of the module

$install_extra = hiera('profiles::config::install_extra')

2) Make the module a parameterized class, which does Hiera lookups automatically

class profiles::config ($install_extra = false) {

    if ($environment =~ /(dev|DEV)/) and ($install_extra == true) {
        class { somesoftware: }
    } 
}

The "= false" part of the parameter is setting a default value if no Hiera value is found, but this is optional. You could just do class profiles::config ($install_extra) { also

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-05-21 10:52:21 -0600

Seen: 951 times

Last updated: May 21 '15