Discussion:
[Puppet Users] hiera and dynamic variables
asq
2012-07-20 13:55:44 UTC
Permalink
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).
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/IhWZNvwQQNgJ.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2012-07-23 07:21:09 UTC
Permalink
Post by asq
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.
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
asq
2012-07-23 09:59:26 UTC
Permalink
W dniu poniedzia³ek, 23 lipca 2012 09:21:09 UTC+2 u¿ytkownik Felix.Frank
Post by Felix Frank
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?
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/sG5AHi_z4nAJ.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Felix Frank
2012-07-23 12:02:48 UTC
Permalink
Post by asq
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
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-***@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Loading...