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? -- Thanks, James "Zeke" Dehnert -- 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/-/YF32x3RhzMcJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hi James, On Tuesday, January 8, 2013 11:19:13 PM UTC, 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? > >I''m not quite sure what you mean by "how far does the define reach in my module". Those variables in the example above are parameters to the define itself and can be used inside that define, you can''t refer to those variables from another container like you can a variable in a class. If you reference a variable outside the current scope you need to make sure that the container the variable is in is declared in the manifest for this node. In short, if you are using $redis::params::version you need to ensure you "include redis::params" or similar. To demonstrate, run the following code with "puppet apply <file>": define test($var = ''woof'') { include dog } class dog { if $var == undef { warning("var = undef") } else { warning("var = ''$var''") } } test { "meow": } #try reference the define variable warning("define var = ''${test::var}''") class one { $foo = ''bar'' include two } class two { warning("foo = ''${foo}''") } include one -Luke> -- > Thanks, > James "Zeke" Dehnert > > > >-- 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/-/gow6N8iiMtMJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.