I apologize if this has been asked before. I''ve tried scanning the docs and the mailing list but I''m probably missing something. I would like to use the defined() operation to see if a file has been defined via a define before defining a default case, but I''m not sure about the parse order. I believe that it won''t work the way that I''m expecting due to the random parse order, but I''d like to find out. Example: site.pp: node default { include "foo" foo::setup_file { "bob": content => "I''m bob!" } } foo.pp: class foo { define setup_file ( $content ) { file { "/tmp/moo": content => $content } } if defined(File["/tmp/moo"]) { } else { foo::setup_file { "default": content => "default" } } } If the nodes are always parsed first, it seems that it would work, however, if not, then I can''t do this. I tried it and it ''seems'' to work, but I may just be getting lucky. Thanks, Trevor --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Aug 19, 2008, at 3:21 PM, Trevor Vaughan wrote:> > I apologize if this has been asked before. I''ve tried scanning the > docs and the mailing list but I''m probably missing something. > > I would like to use the defined() operation to see if a file has been > defined via a define before defining a default case, but I''m not sure > about the parse order. I believe that it won''t work the way that I''m > expecting due to the random parse order, but I''d like to find out.Parse order is not and should never appear random -- it''s only evaluation order that''s not guaranteed. Parse order was previously not always top-down, but it is now. Parsing is always top-down, every ''include'' call results in an immediate evaluation of the specified class(es), and your provided code should work every time.> > Example: > > site.pp: > > node default { > include "foo" > foo::setup_file { "bob": content => "I''m bob!" } > } > > foo.pp: > > class foo { > define setup_file ( $content ) { > file { "/tmp/moo": content => $content } > } > > if defined(File["/tmp/moo"]) { } else { foo::setup_file { "default": > content => "default" } } > } > > If the nodes are always parsed first, it seems that it would work, > however, if not, then I can''t do this. I tried it and it ''seems'' to > work, but I may just be getting lucky.The ''main'' class is always evaluated first (it''s all of the code that''s not in any other construct), then nodes. The key is that each line in the node class is evaluated in order, so if you''ve got the ''include'' call and a file defined, the order in which these are written will matter. Previous versions of Puppet tried to always evaluate function calls first, then resources, but we killed that sometime in the last year. -- Basic research is what I am doing when I don''t know what I am doing. --Wernher von Braun --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Awesome! Thanks Luke. Trevor On Tue, Aug 19, 2008 at 8:58 PM, Luke Kanies <luke@madstop.com> wrote:> > On Aug 19, 2008, at 3:21 PM, Trevor Vaughan wrote: > >> >> I apologize if this has been asked before. I''ve tried scanning the >> docs and the mailing list but I''m probably missing something. >> >> I would like to use the defined() operation to see if a file has been >> defined via a define before defining a default case, but I''m not sure >> about the parse order. I believe that it won''t work the way that I''m >> expecting due to the random parse order, but I''d like to find out. > > Parse order is not and should never appear random -- it''s only > evaluation order that''s not guaranteed. Parse order was previously > not always top-down, but it is now. > > Parsing is always top-down, every ''include'' call results in an > immediate evaluation of the specified class(es), and your provided > code should work every time. > >> >> Example: >> >> site.pp: >> >> node default { >> include "foo" >> foo::setup_file { "bob": content => "I''m bob!" } >> } >> >> foo.pp: >> >> class foo { >> define setup_file ( $content ) { >> file { "/tmp/moo": content => $content } >> } >> >> if defined(File["/tmp/moo"]) { } else { foo::setup_file { "default": >> content => "default" } } >> } >> >> If the nodes are always parsed first, it seems that it would work, >> however, if not, then I can''t do this. I tried it and it ''seems'' to >> work, but I may just be getting lucky. > > The ''main'' class is always evaluated first (it''s all of the code > that''s not in any other construct), then nodes. > > The key is that each line in the node class is evaluated in order, so > if you''ve got the ''include'' call and a file defined, the order in > which these are written will matter. > > Previous versions of Puppet tried to always evaluate function calls > first, then resources, but we killed that sometime in the last year. > > -- > Basic research is what I am doing when I don''t know what I am doing. > --Wernher von Braun > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I now have a correlary to this one... Is there a way to do ''if not defined....''? If there isn''t how should I stub it? Is there a noop{} that I can throw in there? (didn''t find one) Thanks, Trevor On Tue, Aug 19, 2008 at 8:58 PM, Luke Kanies <luke@madstop.com> wrote:> > On Aug 19, 2008, at 3:21 PM, Trevor Vaughan wrote: > >> >> I apologize if this has been asked before. I''ve tried scanning the >> docs and the mailing list but I''m probably missing something. >> >> I would like to use the defined() operation to see if a file has been >> defined via a define before defining a default case, but I''m not sure >> about the parse order. I believe that it won''t work the way that I''m >> expecting due to the random parse order, but I''d like to find out. > > Parse order is not and should never appear random -- it''s only > evaluation order that''s not guaranteed. Parse order was previously > not always top-down, but it is now. > > Parsing is always top-down, every ''include'' call results in an > immediate evaluation of the specified class(es), and your provided > code should work every time. > >> >> Example: >> >> site.pp: >> >> node default { >> include "foo" >> foo::setup_file { "bob": content => "I''m bob!" } >> } >> >> foo.pp: >> >> class foo { >> define setup_file ( $content ) { >> file { "/tmp/moo": content => $content } >> } >> >> if defined(File["/tmp/moo"]) { } else { foo::setup_file { "default": >> content => "default" } } >> } >> >> If the nodes are always parsed first, it seems that it would work, >> however, if not, then I can''t do this. I tried it and it ''seems'' to >> work, but I may just be getting lucky. > > The ''main'' class is always evaluated first (it''s all of the code > that''s not in any other construct), then nodes. > > The key is that each line in the node class is evaluated in order, so > if you''ve got the ''include'' call and a file defined, the order in > which these are written will matter. > > Previous versions of Puppet tried to always evaluate function calls > first, then resources, but we killed that sometime in the last year. > > -- > Basic research is what I am doing when I don''t know what I am doing. > --Wernher von Braun > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---