Sans
2011-Dec-02 15:46 UTC
[Puppet Users] How to import variables from another manifests/file??
How can I globally declare a variable, so that it can be used across the manifests and templates? I tried putting all my variables: --------------------------------- $my_var1 = ''my 1st variable'' $my_var2 = ''my 2nd variable" --------------------------------- in a file, e.g. called "settings.pp" and then try to accessing them from another manifests after importing settings.pp, but that''s absolutely not working. I''m writing a costume module for our and group and I want individual user only to edit the "settings.pp" to put their own value to make this module work for them. How can I make that happen? Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Craig White
2011-Dec-02 16:07 UTC
Re: [Puppet Users] How to import variables from another manifests/file??
On Dec 2, 2011, at 8:46 AM, Sans wrote:> How can I globally declare a variable, so that it can be used across > the manifests and templates? I tried putting all my variables: > > --------------------------------- > $my_var1 = ''my 1st variable'' > $my_var2 = ''my 2nd variable" > --------------------------------- > > in a file, e.g. called "settings.pp" and then try to accessing them > from another manifests after importing settings.pp, but that''s > absolutely not working. I''m writing a costume module for our and group > and I want individual user only to edit the "settings.pp" to put their > own value to make this module work for them. How can I make that > happen? Cheers!!---- presuming that you aren''t using an ENC, you would probably want to simply put the variable in the node definition itself. Craig -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Nigel Kersten
2011-Dec-02 18:14 UTC
Re: [Puppet Users] How to import variables from another manifests/file??
On Fri, Dec 2, 2011 at 7:46 AM, Sans <r.santanu.das@gmail.com> wrote:> How can I globally declare a variable, so that it can be used across > the manifests and templates? I tried putting all my variables: > > --------------------------------- > $my_var1 = ''my 1st variable'' > $my_var2 = ''my 2nd variable" > --------------------------------- > > in a file, e.g. called "settings.pp" and then try to accessing them > from another manifests after importing settings.pp, but that''s > absolutely not working. I''m writing a costume module for our and group > and I want individual user only to edit the "settings.pp" to put their > own value to make this module work for them. How can I make that > happen? Cheers!! > >Assuming you did something like: # modulepath/modules/settings/manifests/init.pp class settings { $my_var1 = "myvar1" } and include the class "settings", from other classes you can refer to it as: $settings::my_var1 Does that help? I noticed you used the word "import". The most frictionless way to use Puppet these days is to avoid import, and to instead structure your classes in modules, and use the autoloader and "include" classes rather than importing manifest files. -- Nigel Kersten Product Manager, Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Sans
2011-Dec-02 19:57 UTC
[Puppet Users] Re: How to import variables from another manifests/file??
Hi Nigel, It''s actually like: "modulepath/modules/mymodule/manifests/ settings.pp" and I was trying to use those variables in the other manifests in "mymodule". I know that autoloader and "include" classes are the way of doing these day but as nothing worked so far, so I tried "import" method as well. I didn''t try "$settings::my_var1" thing yet but I''m giving it a shot now. Cheers, Santanu> > Assuming you did something like: > > # modulepath/modules/settings/manifests/init.pp > class settings { > $my_var1 = "myvar1" > > } > > and include the class "settings", from other classes you can refer to it as: > > $settings::my_var1 > > Does that help? > > I noticed you used the word "import". The most frictionless way to use > Puppet these days is to avoid import, and to instead structure your classes > in modules, and use the autoloader and "include" classes rather than > importing manifest files. > > -- > Nigel Kersten > Product Manager, Puppet Labs-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Nigel Kersten
2011-Dec-02 20:01 UTC
Re: [Puppet Users] Re: How to import variables from another manifests/file??
On Fri, Dec 2, 2011 at 11:57 AM, Sans <r.santanu.das@gmail.com> wrote:> Hi Nigel, > > It''s actually like: "modulepath/modules/mymodule/manifests/ > settings.pp" and I was trying to use those variables in the other > manifests in "mymodule". I know that autoloader and "include" classes > are the way of doing these day but as nothing worked so far, so I > tried "import" method as well. I didn''t try "$settings::my_var1" thing > yet but I''m giving it a shot now. >Thanks for the typo/thinko correction :) Hopefully this documentation should make the right info apparent? http://docs.puppetlabs.com/learning/variables.html If not, please file bugs with us so we can make this easier to understand and discover.> > Cheers, > Santanu > > > > > > Assuming you did something like: > > > > # modulepath/modules/settings/manifests/init.pp > > class settings { > > $my_var1 = "myvar1" > > > > } > > > > and include the class "settings", from other classes you can refer to it > as: > > > > $settings::my_var1 > > > > Does that help? > > > > I noticed you used the word "import". The most frictionless way to use > > Puppet these days is to avoid import, and to instead structure your > classes > > in modules, and use the autoloader and "include" classes rather than > > importing manifest files. > > > > -- > > Nigel Kersten > > Product Manager, Puppet Labs > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > 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. > >-- Nigel Kersten Product Manager, Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Jo Rhett
2011-Dec-02 21:01 UTC
Re: [Puppet Users] How to import variables from another manifests/file??
Don''t confuse them. import tells puppet to read a file it wouldn''t normally. Any .pp file in a module directory will be read, so import means nothing. You might need to set require => Class[''my module::settings''] to ensure that this module is evaluated first so that the variables are available. On Dec 2, 2011, at 11:57 AM, Sans wrote:> It''s actually like: "modulepath/modules/mymodule/manifests/ > settings.pp" and I was trying to use those variables in the other > manifests in "mymodule". I know that autoloader and "include" classes > are the way of doing these day but as nothing worked so far, so I > tried "import" method as well. I didn''t try "$settings::my_var1" thing > yet but I''m giving it a shot now. > > Cheers, > Santanu > > >> >> Assuming you did something like: >> >> # modulepath/modules/settings/manifests/init.pp >> class settings { >> $my_var1 = "myvar1" >> >> } >> >> and include the class "settings", from other classes you can refer to it as: >> >> $settings::my_var1 >> >> Does that help? >> >> I noticed you used the word "import". The most frictionless way to use >> Puppet these days is to avoid import, and to instead structure your classes >> in modules, and use the autoloader and "include" classes rather than >> importing manifest files. >> >> -- >> Nigel Kersten >> Product Manager, Puppet Labs > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > 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. >-- Jo Rhett Net Consonance : consonant endings by net philanthropy, open source and other randomness -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Sans
2011-Dec-03 04:44 UTC
[Puppet Users] Re: How to import variables from another manifests/file??
> > Thanks for the typo/thinko correction :) > > Hopefully this documentation should make the right info apparent?http://docs.puppetlabs.com/learning/variables.html > > If not, please file bugs with us so we can make this easier to understand > and discover.I must be doing something really stupid - I still don''t get it and and trying to understand what I''m doing wrong. This is what I have so far.... ------------------------------------------- # /modulepath/modules/zmfs/manifests/settings.pp: class zmfs::settings { $l_dir = ''/zmfs/ldir.ac.uk'' ....... ....... } # /modulepath/modules/zmfs/manifests/envcheck.pp: class zmfs::envcheck { define env_check($file, $string, $swdir, $refreshonly = ''true'') { ...... ...... } } # /modulepath/modules/zmfs/manifests/config.pp: include zmfs::settings include zmfs::envcheck class zmfs::config { env_check { vo_lhcb: file => ''/etc/profile.d/zfs-env.sh'', string => "$settings::l_dir", ....... ....... } } ----------------------------------------------------------- But all I get an empty string on the target node. Is this what I''m supposed to do? Or I''m still missing something? Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Nigel Kersten
2011-Dec-03 17:56 UTC
Re: [Puppet Users] Re: How to import variables from another manifests/file??
On Fri, Dec 2, 2011 at 8:44 PM, Sans <r.santanu.das@gmail.com> wrote:> > > > Thanks for the typo/thinko correction :) > > > > Hopefully this documentation should make the right info apparent? > http://docs.puppetlabs.com/learning/variables.html > > > > If not, please file bugs with us so we can make this easier to understand > > and discover. > > I must be doing something really stupid - I still don''t get it and and > trying to understand what I''m doing wrong. This is what I have so > far.... > > ------------------------------------------- > # /modulepath/modules/zmfs/manifests/settings.pp: > class zmfs::settings { > $l_dir = ''/zmfs/ldir.ac.uk'' > ....... > ....... > } > > # /modulepath/modules/zmfs/manifests/envcheck.pp: > class zmfs::envcheck { > define env_check($file, $string, $swdir, $refreshonly = ''true'') { > ...... > ...... > } > } > > # /modulepath/modules/zmfs/manifests/config.pp: > include zmfs::settings > include zmfs::envcheck > > class zmfs::config { > env_check { vo_lhcb: > file => ''/etc/profile.d/zfs-env.sh'', > string => "$settings::l_dir", > ....... > ....... > } > } > ----------------------------------------------------------- > > But all I get an empty string on the target node. Is this what I''m > supposed to do? Or I''m still missing something? Cheers!! > >You want to use $zmfs::settings::l_dir You''re fully qualifying the variable, so you need the "full path" to it, including the name of the module it lives in. -- Nigel Kersten Product Manager, Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Sans
2011-Dec-05 11:31 UTC
[Puppet Users] Re: How to import variables from another manifests/file??
Thanks Nigel! That works like a charm. But leaves me with one question and another problem. First the question: If I always need to specify the varable like "$zmfs::settings::l_dir", then waht the significance of the "include" statement (e.g. include zmfs::settings ) in the beginning of the manifest? Now the problem is: If I define "env_check" inside a ''class'' (envcheck.pp in my example code above) and specify "include zmfs::envcheck" in the config.pp, I get this error: ------------------------- err: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type line_check at /etc/puppet/modules/zmfs/manifests/ config.pp:94 on node farm002.. .. ..ac.uk ------------------------- It only works if the envcheck.pp like this way: ------------------------ # /modulepath/modules/zmfs/manifests/envcheck.pp: define env_check($file, $string, $swdir, $refreshonly = ''true'') { ...... ...... } ------------------------ (i.e. without having a class) and use "import envcheck.pp", instead of: include zmfs::envcheck in the manifest. Does any one know what''s going wrong? Cheers, San> > You want to use $zmfs::settings::l_dir > > You''re fully qualifying the variable, so you need the "full path" to it, > including the name of the module it lives in. > > -- > Nigel Kersten > Product Manager, Puppet Labs-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Sans
2011-Dec-05 11:45 UTC
[Puppet Users] Re: How to import variables from another manifests/file??
Sorry for the noise: using "cvmfs::settings::env_check" fixed that. Which makes me thinking again, what''s the importance of the include statement if one always needs to use the fully qualified variable names. Cheers!! -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.
Nigel Kersten
2011-Dec-05 17:26 UTC
Re: [Puppet Users] Re: How to import variables from another manifests/file??
On Mon, Dec 5, 2011 at 3:31 AM, Sans <r.santanu.das@gmail.com> wrote:> Thanks Nigel! That works like a charm. But leaves me with one question > and another problem. First the question: If I always need to specify > the varable like "$zmfs::settings::l_dir", then waht the significance > of the "include" statement (e.g. include zmfs::settings ) in the > beginning of the manifest? >Including the class is what will cause the manifests in that class to be evaluated. Does that help?> > Now the problem is: If I define "env_check" inside a > ''class'' (envcheck.pp in my example code above) and specify "include > zmfs::envcheck" in the config.pp, I get this error: >Make sure the names are the same. e.g. a define called "zmfs::envcheck" should be in $modulepath/modules/zmfs/manifests/envcheck.pp It looks like you''re mixing an extra underscore in there. If you''re doing this with a *define*, then you don''t need to import or include that specific file. Just declare it in that location, and not inside a class. When you use that define, so long as the define is found in a path like the one above where the autoloader will find it, you don''t need to import or include "zmfs::envcheck" anywhere.> > ------------------------- > err: Could not retrieve catalog from remote server: Error 400 on > SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: > Invalid resource type line_check at /etc/puppet/modules/zmfs/manifests/ > config.pp:94 on node farm002.. .. ..ac.uk > ------------------------- > > It only works if the envcheck.pp like this way: > > > ------------------------ > # /modulepath/modules/zmfs/manifests/envcheck.pp: > > define env_check($file, $string, $swdir, $refreshonly = ''true'') { > ...... > ...... > } > ------------------------ > > (i.e. without having a class) and use "import envcheck.pp", instead > of: include zmfs::envcheck in the manifest. Does any one know what''s > going wrong? > > Cheers, > San > > > > > > You want to use $zmfs::settings::l_dir > > > > You''re fully qualifying the variable, so you need the "full path" to it, > > including the name of the module it lives in. > > > > -- > > Nigel Kersten > > Product Manager, Puppet Labs > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > 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. > >-- Nigel Kersten Product Manager, Puppet Labs -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. 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.