Hi, I''m running Puppet 0.23.0 on my servers, and i got something like this: In a classa.pp file (included in site.pp): class A { file { "test1": ... } } In a classb.pp file (included in site.pp): class B { file { "test2": ... } if defined(File["test1"]) { ... do things ... } if defined(File["test2"]) { ... do things ... } } The problem i got is the first "if defined" is not run but the second one is. I''ve done the same thing with "case" statements and the problem is the same. Is my syntax OK or is this a scope problem or a bug in Puppet? Regards
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 12 July 2007, Sébastien Prud''homme wrote:> Hi, > > I''m running Puppet 0.23.0 on my servers, and i got something like this: > > In a classa.pp file (included in site.pp): > > class A { > file { "test1": > ... > } > } > > In a classb.pp file (included in site.pp): > > class B { > file { "test2": > ... > } > > if defined(File["test1"]) { > ... do things ... > } > > if defined(File["test2"]) { > ... do things ... > } > } > > The problem i got is the first "if defined" is not run but the second > one is. I''ve done the same thing with "case" statements and the > problem is the same. > > Is my syntax OK or is this a scope problem or a bug in Puppet?Your syntax looks OK. Two questions for your search: 1) Does your node include both A and B? 2) In which order? Regards, David - -- - - hallo... wie gehts heute? - - *hust* gut *rotz* *keuch* - - gott sei dank kommunizieren wir über ein septisches medium ;) -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGleUW/Pp1N6Uzh0URAlseAJoDv8aGC2nH6UZB/v76WegMmJujAgCcCQac vk90QWX/uEZUHXa3/dBuii8=J5uj -----END PGP SIGNATURE-----
Yes my node include class A and B. First B then A. I thougth the order was not important as Puppet build an unordered graph to represent the different rules for a node. I''ll try to include A before B. 2007/7/12, David Schmitt <david@schmitt.edv-bus.at>:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On Thursday 12 July 2007, Sébastien Prud''homme wrote: > > Hi, > > > > I''m running Puppet 0.23.0 on my servers, and i got something like this: > > > > In a classa.pp file (included in site.pp): > > > > class A { > > file { "test1": > > ... > > } > > } > > > > In a classb.pp file (included in site.pp): > > > > class B { > > file { "test2": > > ... > > } > > > > if defined(File["test1"]) { > > ... do things ... > > } > > > > if defined(File["test2"]) { > > ... do things ... > > } > > } > > > > The problem i got is the first "if defined" is not run but the second > > one is. I''ve done the same thing with "case" statements and the > > problem is the same. > > > > Is my syntax OK or is this a scope problem or a bug in Puppet? > > Your syntax looks OK. > > Two questions for your search: > > 1) Does your node include both A and B? > > 2) In which order? > > Regards, David > > - -- > - - hallo... wie gehts heute? > - - *hust* gut *rotz* *keuch* > - - gott sei dank kommunizieren wir über ein septisches medium ;) > -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.6 (GNU/Linux) > > iD8DBQFGleUW/Pp1N6Uzh0URAlseAJoDv8aGC2nH6UZB/v76WegMmJujAgCcCQac > vk90QWX/uEZUHXa3/dBuii8> =J5uj > -----END PGP SIGNATURE----- > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >
Ok it works now ! The order of the includes is important. If Luke is there (or a Puppet guru), is this the normal behaviour ? Thanks David ! 2007/7/12, Sébastien Prud''homme <sebastien.prudhomme@gmail.com>:> Yes my node include class A and B. First B then A. I thougth the order > was not important as Puppet build an unordered graph to represent the > different rules for a node. > > I''ll try to include A before B. > > 2007/7/12, David Schmitt <david@schmitt.edv-bus.at>: > > -----BEGIN PGP SIGNED MESSAGE----- > > Hash: SHA1 > > > > On Thursday 12 July 2007, Sébastien Prud''homme wrote: > > > Hi, > > > > > > I''m running Puppet 0.23.0 on my servers, and i got something like this: > > > > > > In a classa.pp file (included in site.pp): > > > > > > class A { > > > file { "test1": > > > ... > > > } > > > } > > > > > > In a classb.pp file (included in site.pp): > > > > > > class B { > > > file { "test2": > > > ... > > > } > > > > > > if defined(File["test1"]) { > > > ... do things ... > > > } > > > > > > if defined(File["test2"]) { > > > ... do things ... > > > } > > > } > > > > > > The problem i got is the first "if defined" is not run but the second > > > one is. I''ve done the same thing with "case" statements and the > > > problem is the same. > > > > > > Is my syntax OK or is this a scope problem or a bug in Puppet? > > > > Your syntax looks OK. > > > > Two questions for your search: > > > > 1) Does your node include both A and B? > > > > 2) In which order? > > > > Regards, David > > > > - -- > > - - hallo... wie gehts heute? > > - - *hust* gut *rotz* *keuch* > > - - gott sei dank kommunizieren wir über ein septisches medium ;) > > -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 > > -----BEGIN PGP SIGNATURE----- > > Version: GnuPG v1.4.6 (GNU/Linux) > > > > iD8DBQFGleUW/Pp1N6Uzh0URAlseAJoDv8aGC2nH6UZB/v76WegMmJujAgCcCQac > > vk90QWX/uEZUHXa3/dBuii8> > =J5uj > > -----END PGP SIGNATURE----- > > _______________________________________________ > > Puppet-users mailing list > > Puppet-users@madstop.com > > https://mail.madstop.com/mailman/listinfo/puppet-users > > >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 12 July 2007, Sébastien Prud''homme wrote:> Ok it works now ! The order of the includes is important. > > If Luke is there (or a Puppet guru), is this the normal behaviour ? > > Thanks David !You''re welcome. Thinking a bit more about it, I think that this - order dependent behaviour of defined() - is the only way to handle this special case. Trying a more global solution would lead to all kinds of strange border cases. Consider e.g. mutually depending structures: class A { if defined(File[$b]) { file { $a: ... } } } class B { if defined(File[$a]) { file { $b: ... } } } node test { include A include B } In a global model of defined() I could imagine arguing that node test should get both File[$a] and File[$b], since it would create a "legal" configuration. Implementing such semantics _might_ become a bit messy[1]. I think that the current trade-off is "good-enough" for most cases though. I''ve also added a sentence to that effect to the wiki at http://reductivelabs.com/trac/puppet/wiki/FunctionReference Regards, David [1] Actually this looks like a satisfiability problem (See http://en.wikipedia.org/wiki/Satisfiability) which is NP-complete and thus not even computationally feasible to solve. - -- - - hallo... wie gehts heute? - - *hust* gut *rotz* *keuch* - - gott sei dank kommunizieren wir über ein septisches medium ;) -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGlg/t/Pp1N6Uzh0URArwOAJ0RAAcWbyrxaiAzQe8aywdd8epa0ACeLNA8 FUBM6RxMS17GQ935DPurHB0=0p9j -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 12 July 2007, David Schmitt wrote:> I''ve also added a sentence to that effect to the wiki at > http://reductivelabs.com/trac/puppet/wiki/FunctionReferenceWhich was a stupid idea, since this page is generated from the source. Here is a patch: Index: lib/puppet/parser/functions.rb ==================================================================- --- lib/puppet/parser/functions.rb (revision 2680) +++ lib/puppet/parser/functions.rb (working copy) @@ -162,7 +162,9 @@ type is defined, either as a native type or a defined type, or whether a class is defined. This is useful for checking whether a class is defined and only including it if it is. This function can also test whether a resource has been defined, using resource references - - (e.g., ``if defined(File[''/tmp/myfile''] { ... }``).") do |vals| + (e.g., ``if defined(File[''/tmp/myfile''] { ... }``). Be aware though, that - + contrary to everything else in puppet - defined-ness of resources depends on the order + of the resources with in the manifest.") do |vals| result = false vals.each do |val| case val Regards, David - -- - - hallo... wie gehts heute? - - *hust* gut *rotz* *keuch* - - gott sei dank kommunizieren wir über ein septisches medium ;) -- Matthias Leeb, Uni f. angewandte Kunst, 2005-02-15 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFGlhLe/Pp1N6Uzh0URAl1rAJ0Uwx5lD8QVKi8O3h0URQeti/HAjACeKOOs GqdKMq2dOpOmu14JjcO6a2E=6HB3 -----END PGP SIGNATURE-----
On Jul 12, 2007, at 6:26 AM, David Schmitt wrote: [...]> > [1] Actually this looks like a satisfiability problem (See > http://en.wikipedia.org/wiki/Satisfiability) which is NP-complete > and thus > not even computationally feasible to solve.Exactly. You basically get to choose between not referring to other parts of the configuration, or doing so in an order-dependent way. As to the topological sort, that''s done on the client, long after the resources are all specified. The easiest way to think about is that the language might be order- dependent, but the configuration (once fully specified) will not be. -- One of the Ten Commandments for Technicians (7) Work thou not on energized equipment, for if thou dost, thy fellow workers will surely buy beers for thy widow and console her in other ways. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
On Jul 12, 2007, at 6:39 AM, David Schmitt wrote:> Be aware though, that - > + contrary to everything else in puppet - defined-ness of > resources depends on the order > + of the resources with in the manifestI added a note that says something similar, although worded differently. And thanks for sending it this way -- I fortunately noticed your edit, but yeah, the Reference docs are automatically rewritten. -- The big thieves hang the little ones. -- Czech Proverb --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
--On July 12, 2007 9:33:17 AM -0500 Luke Kanies <luke@madstop.com> wrote:>> [1] Actually this looks like a satisfiability problem (See >> http://en.wikipedia.org/wiki/Satisfiability) which is NP-complete >> and thus >> not even computationally feasible to solve. > > Exactly. You basically get to choose between not referring to other > parts of the configuration, or doing so in an order-dependent way. > > As to the topological sort, that''s done on the client, long after the > resources are all specified. > > The easiest way to think about is that the language might be order- > dependent, but the configuration (once fully specified) will not be. >With the work on beefing up class relationship, will there be an alternative that might help here (like seeing if a class is defined as part of the catalog instead of a specific resource?)
On Jul 12, 2007, at 10:16 AM, Digant C Kasundra wrote:> With the work on beefing up class relationship, will there be an > alternative that might help here (like seeing if a class is defined > as part > of the catalog instead of a specific resource?)I''m not sure I understand your question. The ''defined'' function already works in an order-independent way when testing for classes and definitions, because they''re all defined at parse time, whereas resources are all defined at compile time so that conditionals can stop them being evaluated. -- I am a kind of paranoiac in reverse. I suspect people of plotting to make me happy. --J. D. Salinger --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
--On July 12, 2007 10:27:16 AM -0500 Luke Kanies <luke@madstop.com> wrote:> I''m not sure I understand your question. > > The ''defined'' function already works in an order-independent way when > testing for classes and definitions, because they''re all defined at > parse time, whereas resources are all defined at compile time so that > conditionals can stop them being evaluated.So, something like if (defined(Class[blah]) works?
On Jul 12, 2007, at 11:27 AM, Digant C Kasundra wrote:> So, something like if (defined(Class[blah]) works?Just use defined(blah); works for definitions and classes. -- Nothing is impossible for the man who doesn''t have to do it himself. -- A. H. Weiler --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com