Reputation: 19
I am a newbie on puppet and met some issues as subject, googled for some time but failed with an matched answer. Mys issues is as:
I defined global variables $puppetserver in /etc/puppet/manifests/site.pp as below:
case $domain {
/domain2/:{
$puppetserver = "puppetserver2"
include migrate
}
default:{
$puppetserver = "puppetserver3"
}
}
in node definition of the servers in domain2 in manifests/labs/domain2/nodes.pp
node 'server1.domain2.com' {
$puppetserver = "puppetserver3"
}
the migrate module is used for puppet migration, got from internet as below:
in /etc/puppet/modules/migrate/manifests/config.pp
class migrate::config {
if $puppetserver == undef {
fail('You must define the targeted Puppet master to perform the migration')
}
augeas { 'puppet.conf.migrate':
context => '/files/etc/puppet/puppet.conf/main',
changes => [
"set server $puppetserver",
]
}
}
Since the node 'server1.domain2.com' can match the domain2 setting in site.pp, so it applies the migrate module,what I expected is: it should get the 'puppetserver3' for $puppetserver defined in node block and then be updated in '/etc/puppet/puppet.conf' by the Augeas, but actual result is : it use 'puppetserver2' which was defined in site.pp. I cannot figure out why overriding is not working. Can you kindly help to check what's wrong?
And as a test:
When I tried to move the 'include migrate' module from site.pp to node 'server1.domain2.com' {} block of nodes.pp, it can work as expected. it seems some order when puppet applying manifests, but what I got is that local scope variables will always overrides the variables, is that correct? Thanks a lot for your kindly help.
Upvotes: 0
Views: 323
Reputation: 180201
When you include
a class at top scope as you do, no node block is in scope during its evaluation. That's a good reason to avoid such shenanigans.
Put the include
statement inside the node block, use an ENC to designate the class for inclusion, or maybe use hiera_include()
inside your node block to include it indirectly. Alternatively, use hiera at top scope to set the correct value for the $puppetserver
variable, and thereby take variable shadowing out of the picture.
Upvotes: 1