hiera and dynamic variables

334 views
Skip to first unread message

asq

unread,
Jul 20, 2012, 9:55:44 AM7/20/12
to puppet...@googlegroups.com
hi,

we're currently evaluating hiera to get rid of hordes of global variables and prepare our manifests for next iteration of puppet.
now, we have some variables, used by classes, which set properties based on facts, ie. we set approperiate interface address which should be used on monitoring server, ie:

$nagiosip = $ipaddress_bond0_1234

now, we can convert it to:

class { "nagios::host": ip => $ipaddress_bond0_1234 }

but... we'll need to include this on every single node (now we use node inheritance and just set $nagiosip on top node level for group of hosts that share the same vlan).

is it possible to achieve the same thing with hiera (then we could just set default parameter of nagios::host class to hiera)? we're currently evaluating yaml backend, puppet backend is not as easy to understand to me and i'm not sure if we can mix both (ie. define separate calling_modules and search hierarchies for both).


Felix Frank

unread,
Jul 23, 2012, 3:21:09 AM7/23/12
to puppet...@googlegroups.com
On 07/20/2012 03:55 PM, asq wrote:
>
> class { "nagios::host": ip => $ipaddress_bond0_1234 }
>
> but... we'll need to include this on every single node (now we use node
> inheritance and just set $nagiosip on top node level for group of hosts
> that share the same vlan).

This end could be trivially met by putting this class declaration in a
scope that is present for all your nodes. Perhaps a "default" class or
similar.

The class parameter should be assigned directly from hiera. Failing
that, just assign a "nagiosip" value in hiera an put a

class { "nagios::host": ip => hiera("nagiosip") }

in your global scope.

asq

unread,
Jul 23, 2012, 5:59:26 AM7/23/12
to puppet...@googlegroups.com
W dniu poniedziałek, 23 lipca 2012 09:21:09 UTC+2 użytkownik Felix.Frank napisał:
This end could be trivially met by putting this class declaration in a
scope that is present for all your nodes. Perhaps a "default" class or
similar.

The class parameter should be assigned directly from hiera. Failing
that, just assign a "nagiosip" value in hiera an put a

class { "nagios::host": ip => hiera("nagiosip") }

in your global scope.

i don't want to define nagiosip - it should be inherited from fact (current set IP address on given node). ie.
project A: $nagiosip = $ipaddress_bond0_1234
project B: $nagiosip = $ipaddress_bond0_1235
project C: $nagiosip = $ipaddress_eth2
project D: $nagiosip = $ipaddress_bond0_555

in our current setup we have:

class baseclass {
    # this is class mandatory for every production node
    .
    .
    include nagios::host
}

node projectA {
    # production vlan for projectA is 1234
    $nagiosip = $ipaddress_bond0_1234
}

node foo inherits projectA {
     include baseclass
}

can we do that without global variables?

Felix Frank

unread,
Jul 23, 2012, 8:02:48 AM7/23/12
to puppet...@googlegroups.com
On 07/23/2012 11:59 AM, asq wrote:
> i don't want to define nagiosip - it should be inherited from fact
> (current set IP address on given node). ie.
> project A: $nagiosip = $ipaddress_bond0_1234
> project B: $nagiosip = $ipaddress_bond0_1235
> project C: $nagiosip = $ipaddress_eth2
> project D: $nagiosip = $ipaddress_bond0_555

This is what I meant, sort of.

Your hiera stores will probably have a "project" hierarchy layer. What
you want to do is add a "vlan" value to this layer. Each node can lookup
hiera("vlan") then, e.g. $vlan = hiera("vlan").

In your baseclass (or nagios::host class proper), you can retrieve the
IP e.g. via
inline_template("<%= scope.lookupvar('ipaddress_bond0_'+vlan) %>")

(code is untested)

HTH
Felix
Reply all
Reply to author
Forward
0 new messages