Oded
2010-Feb-10 17:09 UTC
[Puppet Users] using (possibly) undefined out of scope variables in an erb template
I''m trying to use (possibly) undefined variables that are not in the scope of my class in an erb template. How do I combine this : <% if has_variable?("myvar") then %> myvar has <%= myvar %> value <% end %> with this : <%= scope.lookupvar(myclass::myvar) %> The idea is to get the iptables template to go through all the classes assigned to a machine and add lines on relevant classes only(by searching for a specific variable in that class),this way I will not be forced to edit the iptables template/class every time another module needs to change its iptable settings. Without checking for undefined variables my code looks like this : <% classes.each do |current_class| -%> <% scope.lookupvar(current_class::iptables_input_tags) %> <% end -%> Oded -- 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.
Ohad Levy
2010-Feb-11 20:33 UTC
Re: [Puppet Users] using (possibly) undefined out of scope variables in an erb template
you might be hitting - http://projects.reductivelabs.com/issues/2309 Ohad On Thu, Feb 11, 2010 at 1:09 AM, Oded <oded.benozer@gmail.com> wrote:> I''m trying to use (possibly) undefined variables that are not in the > scope of my class in an erb template. > How do I combine this : > > <% if has_variable?("myvar") then %> > myvar has <%= myvar %> value > <% end %> > > with this : > <%= scope.lookupvar(myclass::myvar) %> > > > The idea is to get the iptables template to go through all the classes > assigned to a machine and add lines on relevant classes only(by > searching for a specific variable in that class),this way I will not > be forced to edit the iptables template/class every time another > module needs to change its iptable settings. > > Without checking for undefined variables my code looks like this : > > <% classes.each do |current_class| -%> > <% scope.lookupvar(current_class::iptables_input_tags) %> > <% end -%> > > > > Oded > > > -- > 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.
Oded
2010-Feb-13 18:35 UTC
[Puppet Users] Re: using (possibly) undefined out of scope variables in an erb template
Actually I am trying to go around it :) I choose to use the classes array because of the an ordering issue I encountered while trying to build an array of iptables rules : the template would get evaluated before some the classes would get the chance to add lines to the array. I''m hoping that by using the classes array (which is in its finale state before the classes start to run) I can avoid the ordering issue. my question was about the ruby syntax of checking for undefined out of scope variables (or are you trying to tell me that theres no way around it ?). Oded On Feb 11, 10:33 pm, Ohad Levy <ohadl...@gmail.com> wrote:> you might be hitting -http://projects.reductivelabs.com/issues/2309 > > OhadOn Thu, Feb 11, 2010 at 1:09 AM, Oded <oded.beno...@gmail.com> wrote: > > I''m trying to use (possibly) undefined variables that are not in the > > scope of my class in an erb template. > > How do I combine this : > > > <% if has_variable?("myvar") then %> > > myvar has <%= myvar %> value > > <% end %> > > > with this : > > <%= scope.lookupvar(myclass::myvar) %> > > > The idea is to get the iptables template to go through all the classes > > assigned to a machine and add lines on relevant classes only(by > > searching for a specific variable in that class),this way I will not > > be forced to edit the iptables template/class every time another > > module needs to change its iptable settings. > > > Without checking for undefined variables my code looks like this : > > > <% classes.each do |current_class| -%> > > <% scope.lookupvar(current_class::iptables_input_tags) %> > > <% end -%> > > > Oded > > > -- > > 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@google groups.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.
Oded
2010-Feb-23 14:17 UTC
[Puppet Users] Re: using (possibly) undefined out of scope variables in an erb template
Got it ! <% classes.each do |current_class| -%> <% if has_variable?(current_class + "::iptable_rule_chain") then -%> <%= scope.lookupvar(current_class + "::iptable_rule_chain") %> <% end -%> <% end -%> So easy ,all that time I was trying to use Bash style string concatenation , which for some strange reason didn''t work :) Now each class that has a variable named "iptable_rule_chain" adds a line to my template, yey ! Theres a new issue with scoping now : if i use this variable in a class that calls other classes I get duplicate lines as the same variable is "in the scope" of several classes ,currently I write the manifests around this issue (by using "subclasses"),but it would be nice if I could control the scoping of each variable. I prefer this solution to using Augeas as it is more "deterministic" , I know exactly how my file will look like without considering its current state. On Feb 13, 8:35 pm, Oded <oded.beno...@gmail.com> wrote:> Actually I am trying to go around it :) > I choose to use the classes array because of the an ordering issue I > encountered while trying to build an array of iptables rules : the > template would get evaluated before some the classes would get the > chance to add lines to the array. > I''m hoping that by using the classes array (which is in its finale > state before the classes start to run) I can avoid the ordering issue. > my question was about the ruby syntax of checking for undefined out > of scope variables (or are you trying to tell me that theres no way > around it ?). > > Oded > > On Feb 11, 10:33 pm, Ohad Levy <ohadl...@gmail.com> wrote: > > > > > you might be hitting -http://projects.reductivelabs.com/issues/2309 > > > OhadOn Thu, Feb 11, 2010 at 1:09 AM, Oded <oded.beno...@gmail.com> wrote: > > > I''m trying to use (possibly) undefined variables that are not in the > > > scope of my class in an erb template. > > > How do I combine this : > > > > <% if has_variable?("myvar") then %> > > > myvar has <%= myvar %> value > > > <% end %> > > > > with this : > > > <%= scope.lookupvar(myclass::myvar) %> > > > > The idea is to get the iptables template to go through all the classes > > > assigned to a machine and add lines on relevant classes only(by > > > searching for a specific variable in that class),this way I will not > > > be forced to edit the iptables template/class every time another > > > module needs to change its iptable settings. > > > > Without checking for undefined variables my code looks like this : > > > > <% classes.each do |current_class| -%> > > > <% scope.lookupvar(current_class::iptables_input_tags) %> > > > <% end -%> > > > > Oded > > > > -- > > > 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@google groups.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.