Rich Rauenzahn
2011-Feb-02 17:47 UTC
[Puppet Users] How to include the Scope(...) in a generated string?
I''d like to include similar information that notice() spits out in a file I am generating -- basically so that anyone looking at the generated file (actually a file fragment) could trace it back to the class that is generating the entry. Using $name within the file fragment is the closest I am getting to what I want -- is there anything better? -- 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.
Dan Bode
2011-Feb-02 18:04 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On Wed, Feb 2, 2011 at 9:47 AM, Rich Rauenzahn <rrauenza@gmail.com> wrote:> I''d like to include similar information that notice() spits out in a > file I am generating -- basically so that anyone looking at the > generated file (actually a file fragment) could trace it back to the > class that is generating the entry. >you could use $module_name, assuming you are using modules, or even better, Here is some code to print all of the current variable names in the scopes symbol table: class fooperi { $foo = inline_template("<% scope.to_hash.keys.each do |k| %> <%= k %><% end %>") notice($foo) } for you requirement, its probably best to print the name of the scope: $foo = inline_template("<%= scope.to_s %>")> Using $name within the file fragment is the closest I am getting to > what I want -- is there anything better? > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- 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-Feb-02 18:28 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On Wed, Feb 2, 2011 at 9:47 AM, Rich Rauenzahn <rrauenza@gmail.com> wrote:> I''d like to include similar information that notice() spits out in a > file I am generating -- basically so that anyone looking at the > generated file (actually a file fragment) could trace it back to the > class that is generating the entry. >Are you generating it with a template? One option is to turn on VCS tags such as $Id$ and embed that info in a comment in your erb template, as often being able to trace the VCS repo path is faster than dereferencing classes and environments to work out where the actual file is.> > Using $name within the file fragment is the closest I am getting to > what I want -- is there anything better? > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- 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.
John Warburton
2011-Feb-03 00:57 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On 3 February 2011 05:04, Dan Bode <dan@puppetlabs.com> wrote:> > Here is some code to print all of the current variable names in the scopes > symbol table: > > class fooperi { > $foo = inline_template("<% scope.to_hash.keys.each do |k| %> > <%= k %><% end %>") > notice($foo) > } >For those of us with next to no ruby or knowledge on where to look inside puppet for variables, this is brilliant! I have on occasion wondered about this I would love to see that in http://docs.puppetlabs.com/guides/templating.html in the "Access to defined tags and classes" section. I have created a ticket for that - https://projects.puppetlabs.com/issues/6124 John -- 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.
Brian Gallew
2011-Feb-03 01:18 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On Feb 2, 2011, at 4:57 PM, John Warburton wrote:> I would love to see that in http://docs.puppetlabs.com/guides/templating.html in the "Access to defined tags and classes" section. I have created a ticket for that -https://projects.puppetlabs.com/issues/6124Sadly, there''s also a great need to update that section to reflect the reality that the classes variable can never be relied upon to be in any way complete. -- 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.
Nick Fagerlund
2011-Feb-03 01:50 UTC
[Puppet Users] Re: How to include the Scope(...) in a generated string?
On it. (Thanks for the example, Dan; that''s pretty sweet.) Brian, what problem do you tend to see with the classes array? Does it look like an order dependency? Is it just a crapshoot as to whether a given class is in the list, or is there a method to it? On Feb 2, 5:18 pm, Brian Gallew <g...@gallew.org> wrote:> On Feb 2, 2011, at 4:57 PM, John Warburton wrote: > > > I would love to see that inhttp://docs.puppetlabs.com/guides/templating.htmlin the "Access to defined tags and classes" section. I have created a ticket for that -https://projects.puppetlabs.com/issues/6124 > > Sadly, there''s also a great need to update that section to reflect the reality that the classes variable can never be relied upon to be in any way complete.-- 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.
Nick Fagerlund
2011-Feb-03 02:00 UTC
[Puppet Users] Re: How to include the Scope(...) in a generated string?
*EXPERIMENTS* Huh, it seems to return the DECLARED classes, not the defined ones, i.e. it can only see the modules and classes that are being applied to this particular node. OK, I could see an argument for that making sense. BUT: It also includes the names of any `node` constructs that match it (these are nodes defined in manifests, not from an ENC), and for some reason classes set via an ENC show up twice. I don''t understand that. Also, there''s one mystery class from Mars in there called "settings." What''s THAT about. On Feb 2, 5:50 pm, Nick Fagerlund <nick.fagerl...@puppetlabs.com> wrote:> On it. (Thanks for the example, Dan; that''s pretty sweet.) > > Brian, what problem do you tend to see with the classes array? Does it > look like an order dependency? Is it just a crapshoot as to whether a > given class is in the list, or is there a method to it? > > On Feb 2, 5:18 pm, Brian Gallew <g...@gallew.org> wrote: > > > > > > > > > On Feb 2, 2011, at 4:57 PM, John Warburton wrote: > > > > I would love to see that inhttp://docs.puppetlabs.com/guides/templating.htmlinthe "Access to defined tags and classes" section. I have created a ticket for that -https://projects.puppetlabs.com/issues/6124 > > > Sadly, there''s also a great need to update that section to reflect the reality that the classes variable can never be relied upon to be in any way complete.-- 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.
Brian Gallew
2011-Feb-03 03:04 UTC
Re: [Puppet Users] Re: How to include the Scope(...) in a generated string?
My experience with it is that it only includes declared/included classes (which matches my desire anyway), but that the list of classes is ... somewhat random. It will always include the classes in the chain of the test, but other classes are more random. A short example: class one{ include two;include three} class two {notice "two: $classes"} class three {notice "three: $classes" } There will be two notices printed, with two possible variations each, depending upon what the compiler chooses to do this time: two: one two two: one two three (order may vary) three: one three three: one two three (again, order may vary) In my case, I''m evaluating template("ssh/sshd_config.erb") inside my "minimal" class, because *every* host has ssh, but the set of users allowed to login to each host varies depending upon the total set of classes involved. If I include role::web_server, then the web server manager needs to be able to login. If I include role::dev, then all of the developers should have access. A host may have multiple roles, and thus the need for some reasonable way of determining what classes are associated with the node. When I ran 2.6.1, this worked as desired (I *think*). After updating to 2.6.3, it almost never worked as desired. If I had to guess, I''d say that the evaluation of templates (and possibly inline_templates) previously happened after the first pass at parsing when the list of classes would be complete except for those whose inclusion is predicated on the inline_template() evaluations. Now it''s clear that all the templates (inline or not) are evaluated at the point they are encountered, which should be(!) in a fixed order, though it seems (sorry, I haven''t exhaustively tested) to vary somewhat from run to run. On Wed, Feb 2, 2011 at 6:00 PM, Nick Fagerlund < nick.fagerlund@puppetlabs.com> wrote:> *EXPERIMENTS* > > Huh, it seems to return the DECLARED classes, not the defined ones, > i.e. it can only see the modules and classes that are being applied to > this particular node. OK, I could see an argument for that making > sense. BUT: It also includes the names of any `node` constructs that > match it (these are nodes defined in manifests, not from an ENC), and > for some reason classes set via an ENC show up twice. I don''t > understand that. Also, there''s one mystery class from Mars in there > called "settings." What''s THAT about. > > On Feb 2, 5:50 pm, Nick Fagerlund <nick.fagerl...@puppetlabs.com> > wrote: > > On it. (Thanks for the example, Dan; that''s pretty sweet.) > > > > Brian, what problem do you tend to see with the classes array? Does it > > look like an order dependency? Is it just a crapshoot as to whether a > > given class is in the list, or is there a method to it? > > > > On Feb 2, 5:18 pm, Brian Gallew <g...@gallew.org> wrote: > > > > > > > > > > > > > > > > > On Feb 2, 2011, at 4:57 PM, John Warburton wrote: > > > > > > I would love to see that inhttp:// > docs.puppetlabs.com/guides/templating.htmlinthe "Access to defined tags > and classes" section. I have created a ticket for that - > https://projects.puppetlabs.com/issues/6124 > > > > > Sadly, there''s also a great need to update that section to reflect the > reality that the classes variable can never be relied upon to be in any way > complete. > > -- > 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<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- 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.
Hiran Chaudhuri
2011-Feb-03 07:36 UTC
Re: [Puppet Users] Re: How to include the Scope(...) in a generated string?
<body>Hi, Brian.<br /><br />Not knowing about the structures inside puppet my guess would be that the scope is evaluated before the classes are applied.<br />Their content seems complete in both cases you mention. However the order may vary. This can be the case if the variables are held internally in a HashMap or similar.<br />Maybe for easier comparison during debugging the scope should be sorted alphabetically before printing.<br /><br />Hiran<br /><br /><b><br />Von:</b> "Brian Gallew" <geek@gallew.org><br /><span style="font-size: 9pt;"><span style="font-family: verdana,geneva;"><span style="background-color: transparent;"><span style="color: #000000;"><span style="color: #000000;"> <blockquote style="border-left: 2px solid blue; margin-left: 5px; padding-left: 5px; padding-top: 5px;"><b></b>There will be two notices printed, with two possible variations each, depending upon what the compiler chooses to do this time:<br /><br />two: one two<br />two: one two three (order may vary)<br /><br />three: one three<br />three: one two three (again, order may vary)<br /><br />[...]<br /><br />If I had to guess, I''d say that the evaluation of templates (and possibly inline_templates) previously happened after the first pass at parsing when the list of classes would be complete except for those whose inclusion is predicated on the inline_template() evaluations. Now it''s clear that all the templates (inline or not) are evaluated at the point they are encountered, which should be(!) in a fixed order, though it seems (sorry, I haven''t exhaustively tested) to vary somewhat from run to run.<br /><br /></blockquote> </span></span></span></span></span> <br><br><table cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="#000000"><img src="https://img.web.de/p.gif" width="1" height="1" border="0" alt="" /></td></tr><tr><td style="font-family:verdana; font-size:12px; line-height:17px;">Empfehlen Sie WEB.DE DSL Ihren Freunden und Bekannten und wir <br>belohnen Sie mit bis zu 50,- Euro! <a href="https://freundschaftswerbung.web.de"><b>https://freundschaftswerbung.web.de</b></a></td></tr></table> </body> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups "Puppet Users" group.<br /> To post to this group, send email to puppet-users@googlegroups.com.<br /> To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.<br /> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.<br />
John Warburton
2011-Feb-10 04:36 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On 3 February 2011 05:04, Dan Bode <dan@puppetlabs.com> wrote:> class fooperi { > $foo = inline_template("<% scope.to_hash.keys.each do |k| %> > <%= k %><% end %>") > notice($foo) > } >so I have this running nicely in a file - but I''d love to have the results sorted. Putting ".sort" at random places on the hash gives me errors. Any pointers for a ruby newby? Thanks John -- 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.
Nan Liu
2011-Feb-10 05:04 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On Wed, Feb 9, 2011 at 8:36 PM, John Warburton <jwarburton@gmail.com> wrote:> On 3 February 2011 05:04, Dan Bode <dan@puppetlabs.com> wrote: > >> >> class fooperi { >> $foo = inline_template("<% scope.to_hash.keys.each do |k| %> >> <%= k %><% end %>") >> notice($foo) >> } > > so I have this running nicely in a file - but I''d love to have the results > sorted. Putting ".sort" at random places on the hash gives me errors. Any > pointers for a ruby newby?Not sure if there''s a better way. Convert all Hash key to string, so it doesn''t choke on the array sort: $foo = inline_template("<% scope.to_hash.keys.collect{|x| x.to_s}.sort.each do |k| %><%= k %><% end %>") notice($foo) HTH Nan -- 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.
John Warburton
2011-Feb-10 05:48 UTC
Re: [Puppet Users] How to include the Scope(...) in a generated string?
On 10 February 2011 16:04, Nan Liu <nan@puppetlabs.com> wrote:> > Not sure if there''s a better way. Convert all Hash key to string, so > it doesn''t choke on the array sort: > > $foo = inline_template("<% scope.to_hash.keys.collect{|x| > x.to_s}.sort.each do |k| %><%= k %><% end %>") > notice($foo) > > Thanks Nan - it works perfectly - even if it looks like a bit of voodoo :-)But then, so did perl when I first started using it... John -- 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.