<Derek.Whayman@barclayscapital.com>
2007-Oct-29 17:38 UTC
Setting variables in modules - order important?
Puppeteers, For some reason I have to assign my variable before I include my class for the assignment to ''take''. I though the ordering was immaterial. Am I doing something wrong (again) or is this a funny? ----------------------- This works: <0> sa_dewha@engpsr0000.intranetdev.barcapdev.com (0 jobs) /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/examples % cat setup.pp $int_var = "Set in setup.pp example" include ztest::setup <0> sa_dewha@engpsr0000.intranetdev.barcapdev.com (0 jobs) /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/examples % ./test.sh; cat /var/tmp/test ++ pwd + MODULEDIR=/users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztes t/examples/../.. + puppet --color=false -v --server=localhost + --modulepath=/users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules + /ztest/examples/../.. --libdir=/var/lib/puppet/plugins ./setup.pp info: Autoloaded module ztest notice: ztest::setup: Hello. Testing. notice: ztest::setup: int_var = Set in setup.pp example TEST FILE int_var = Set in setup.pp example ----------------------- This does not: <0> sa_dewha@engpsr0000.intranetdev.barcapdev.com (0 jobs) /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/examples % cat setup.pp include ztest::setup $int_var = "Set in setup.pp example" <0> sa_dewha@engpsr0000.intranetdev.barcapdev.com (0 jobs) /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/examples % ./test.sh ++ pwd + MODULEDIR=/users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztes t/examples/../.. + puppet --color=false -v --server=localhost + --modulepath=/users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules + /ztest/examples/../.. --libdir=/var/lib/puppet/plugins ./setup.pp info: Autoloaded module ztest notice: ztest::setup: Hello. Testing. notice: ztest::setup: int_var Failed to parse template ztest/test: Could not find value for ''int_var'' at /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/examples /../../ztest/manifests/init.pp:13 ----------------------- Support files: <0> sa_dewha@engpsr0000.intranetdev.barcapdev.com (0 jobs) /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/manifest s % cat init.pp class ztest::setup { notice "Hello. Testing." notice "int_var = $int_var" file { "/var/tmp/test": content => template("ztest/test") } } <0> sa_dewha@engpsr0000.intranetdev.barcapdev.com (0 jobs) /users/unix/sa_dewha/SVNCheckOut/bootstrap/puppet/modules/ztest/template s % cat test TEST FILE int_var = <%= int_var %> ----------------------- Derek ------------------------------------------------------------------------ For important statutory and regulatory disclosures and more information about Barclays Capital, please visit our web site at http://www.barcap.com. Internet communications are not secure and therefore the Barclays Group does not accept legal responsibility for the contents of this message. Although the Barclays Group operates anti-virus programmes, it does not accept responsibility for any damage whatsoever that is caused by viruses being passed. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Barclays Group. Replies to this email may be monitored by the Barclays Group for operational or business reasons. Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP. This email may relate to or be sent from other members of the Barclays Group. ------------------------------------------------------------------------
On Oct 29, 2007, at 12:38 PM, <Derek.Whayman@barclayscapital.com> wrote:> For some reason I have to assign my variable before I include my class > for the assignment to ''take''. I though the ordering was > immaterial. Am > I doing something wrong (again) or is this a funny?This is something I''ve actually fixed in the code, although I have not yet determined whether I''ll be able to include it in the next release, because it''s a huge chunk of work that might introduce more change than I''m comfortable with right now. Basically, in the current release, ''include'' evaluates the class immediately. What I''ve done is convert it to do lazy evaluation -- it only evaluates the included class once the whole including class is evaluated. This works by creating a ''class'' resource internally, one that behaves almost exactly as a defined resource does. Puppet was already iterating over these defined resources until all remaining resources were builtin (e.g., file, service); now it does the same thing with class resources. This has a strange side effect in that you don''t have any guarantee of when a given class will be evaluated, other than that it''s after the including class is done being evaluated. -- Tobacco stocks have taken a big tumble," says Jay Leno. "Phillip Morris fell 6 points. They lost so much money they may have to lay off two senators." --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Digant C Kasundra
2007-Nov-14 20:22 UTC
Re: Setting variables in modules - order important?
--On Monday, October 29, 2007 5:38 PM +0000 Derek.Whayman@barclayscapital.com wrote:> For some reason I have to assign my variable before I include my class > for the assignment to ''take''. I though the ordering was immaterial. Am > I doing something wrong (again) or is this a funny?There as been much discussion about variables and overriding variables and making variables order dependent. In my opinion, this is a violation of what Puppet is trying to strive for, which is order independent, idempotency. I personally prefer explicitly using declarations and overrides. So in cases were we have a default "variable" and then are interested in possibly changing that "variable" in other classes, we simply use a definition to handle that variable and doing what it must with that variable and override that definition as needed. This works great and I think it makes manifests easier to follow because you can see where a definition is being declared and where a definition is being overridden instead of trying to trace through chains of includes to see where things are being changed.
Reasonably Related Threads
- Command line vs config file override for configuration params
- Overriding resources in a define in a module - can''t get syntax right
- Creating a manifests ''release'' under SVN; trouble with SVN headers
- Warning for Fedora Core users
- Order of getpwnam call in Get_Pwnam_internals.