In the scope of one class, I need to be able to access a variable from another class. The variable is passed as a parameter, e.g.
class parameterized_class (
$param1,
) {
...
}
and
class other_class () {
include parameterized_class
Class['parameterized_class'] -> Class['other_class']
$local_var = $parameterized_class::param1
}
With an example usage of:
node default {
class { 'parameterized_class':
param1 => 'somevalue',
}
class { 'other_class': }
}
The above example does not work, as I get an error that looks roughly like:
Must pass param1 to Class[Parameterized_class] at /path/to/modules/parameterized_class/manifests/init.pp:1 on node localhost
Obviously, include is trying to declare parameterized_class without passing any parameters. But from the docs, I can see that include allows for a class to have been already previously declared, and since I have the parameterized_class declaration as a dependency of other_class, I don't understand how I could be getting this error.
I'm using Puppet 3.4.3, the version available on Ubuntu 14.04 Trusty
How should I go about retrieving the value of the $param1 in parameterized_class from within other_class's scope? Is it not possible to use include on parameterized classes?
includewith parameterized classes, but that is not going to help you achieve what you want here. Third, havingClass['parameterized_class'] -> Class['other_class']inside theother_classdefinition with the way you are trying to do things is probably going to end up causing problems eventually. Given this and what you are trying to do, the easiest ways to fix your problem is either hiera or remove theinclude parameterized_classline. - Matt Schuchard