On Tuesday, January 8, 2013 5:19:13 PM UTC-6, jdehnert wrote:
>
> I want to pass a few variables through to the other files in a module.  I 
> have a define statement that sets one default...
>
>     define redis::install ( $port = 6397, $version )
>
> What I am unclear on is how far does this define reach in my module?  For 
> instance, do I need to have everything that uses these variables included 
> in the same file as the define, or if I put the define in init.pp can I use 
> those variables in the config.pp file?
>
>
It sounds like you may think Puppet's 'define' is analogous to the C 
preprocessor's #define directive, but it's not like that at all.

Puppet's 'define' allows you to define custom resource types, instances of 
which you may then declare elsewhere in your manifests.  The parameter list 
given in the 'define' statement enumerates the parameters the custom type 
will recognize, and allows you to declare default values for some or all of 
them.

Again, this is not like a CPP macro: Puppet *does not* interpolate 
definition bodies where instances are declared.  Declaring a definition 
instance is for all intents and purposes exactly like declaring an instance 
of a native resource type.  Therefore, the instances have global scope once 
they are declared, like any other resource, but you cannot interrogate them 
for their property values (also like any other resource).

As for your underlying objective, you have several alternatives, among them

   - Record your data in class (or global) variables, and access them from 
   anywhere via their qualified names.
   - Load your data as needed from an external source, via hiera or a 
   custom data-access function
   - Pass data down the declaration tree via definition and / or class 
   parameters

Those can be mixed and matched as you like, but it is my custom to admonish 
people against using class parameters (as opposed to class variables, which 
are fine) for this purpose.  There are good reasons to avoid class 
parameters, but I will spare you and everyone the harangue, unless you 
really want to hear it.


John

-- 
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/-/hrJAdDUqoRIJ.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to