On 2014-24-07 14:27, Werner Flamme wrote:
em...@benjaminmertens.de [24.07.2014 12:42]:
# site.pp
define iterateSystemRole {
case $name {
'app1': {
include app1
$defineVariable = 'content'
}
'app2': {
include app2
}
default: { }
}
}
But the variable $::iterateSystemRole::defineVariable is always undefined.
So i cant get the content from $defineVariable.
How can i get this working?
I googled a lot but did not find a way... I think its an issue with scoping
but i hope there is a way to get this working...
Did you try to swap the lines, so that they read
$defineVariable = 'content'
include app1
Does this help?
That does not work because the variables set in a define are local and
private, there is no way that variable can be accessed from within an
included class.
Depending on puppet version, the scoping rules are slightly different
wrt. what can be accessed. In older versions you could use dynamic
scoping by changing your define to a class, but that does not work in
newer versions (dynamic scoping has been deprecated and removed because
of its many bad side effects).
You may instead want to use parameterized classes, and instead of an
include do this:
class { app1: defined_variable => 'content' }
and define the class like this:
class app1($defined_variable) {
# ...
}
This also has the advantage that you can control the configuration using
external data lookup via hiera instead of having your own logic
in puppet for this.
- henrik
--
Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/
--
You received this message because you are subscribed to the Google Groups "Puppet
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/lqr4uj%24v7f%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.