Dick Davies
2009-Jun-10 22:20 UTC
[Puppet Users] Any way to stop has_variable? throwing errors?
I''m using a primitive template to build my iptables rulesets. It''s all in a branch on my github repo at http://github.com/rasputnik/babysteps-puppet/tree/templated-iptables template that looks like: <% if has_variable?(''httpd::open_firewall'') %> -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT <% end -%> (see http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/iptables/templates/iptables.erb ) i then set a variable in the httpd module like this: class httpd { $open_firewall = ''on'' #.... rest of httpd class def. } [ http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/httpd/manifests/init.pp ] The idea being that if a node has ''include httpd'', then when it runs ''include iptables'' it''ll open the right port. This works fine for classes that include httpd. The trouble is that i get this error on nodes that don''t : [root@node03 ~]# puppetd -tv info: Retrieving plugins err: Could not retrieve catalog: Failed to parse template iptables/iptables.erb: Class httpd has not been evaluated so its variables cannot be referenced at /etc/puppet/modules/iptables/manifests/init.pp:11 on node node03.pixie warning: Not using cache on failed catalog To my mind, that should be a warning, not an error. Is there any ''guard'' I can put in my template to stop this blowing up? I did try: <% if has_variable?(''httpd'') && has_variable?(''httpd::open_firewall'') %> but the first clause is always false, even on nodes that ''include httpd''. Sorry this has been a bit longwinded, but I''m a bit stumped here. Thanks in advance for any tips. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Trevor Vaughan
2009-Jun-11 03:28 UTC
[Puppet Users] Re: Any way to stop has_variable? throwing errors?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Someone might give you a better answer, but try: <% if tags.index(''httpd'') && has_variable?(''httpd::open_firewall'') %> This *may not* work due to file parsing order, but I *think* that it will. Trevor Dick Davies wrote:> I''m using a primitive template to build my iptables rulesets. > It''s all in a branch on my github repo at > > http://github.com/rasputnik/babysteps-puppet/tree/templated-iptables > > template that looks like: > > <% if has_variable?(''httpd::open_firewall'') %> > -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT > <% end -%> > > (see http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/iptables/templates/iptables.erb > ) > > i then set a variable in the httpd module like this: > > class httpd { > $open_firewall = ''on'' > #.... rest of httpd class def. > } > > [ http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/httpd/manifests/init.pp > ] > > The idea being that if a node has ''include httpd'', then when it runs > ''include iptables'' > it''ll open the right port. > > This works fine for classes that include httpd. The trouble is that i > get this error on > nodes that don''t : > > [root@node03 ~]# puppetd -tv > info: Retrieving plugins > err: Could not retrieve catalog: Failed to parse template > iptables/iptables.erb: Class httpd has not been evaluated so its > variables cannot be referenced at > /etc/puppet/modules/iptables/manifests/init.pp:11 on node node03.pixie > warning: Not using cache on failed catalog > > > To my mind, that should be a warning, not an error. > > Is there any ''guard'' I can put in my template to stop this blowing up? > > I did try: > > <% if has_variable?(''httpd'') && has_variable?(''httpd::open_firewall'') %> > > but the first clause is always false, even on nodes that ''include httpd''. > > > Sorry this has been a bit longwinded, but I''m a bit stumped here. > Thanks in advance for > any tips. > > >-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkowedoACgkQyjMdFR1108Dh0gCfWz7tn6/5+K2w9LZK2P+ajsab hy4An1ogD2dP3yj9wuGpn4v/Q1dKmoEa =7UvV -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dick Davies
2009-Jun-11 09:42 UTC
[Puppet Users] Re: Any way to stop has_variable? throwing errors?
Hi Trevor, thanks for the idea. On Thu, Jun 11, 2009 at 4:28 AM, Trevor Vaughan<peiriannydd@gmail.com> wrote:> Someone might give you a better answer, but try: > > <% if tags.index(''httpd'') && has_variable?(''httpd::open_firewall'') %> > > This *may not* work due to file parsing order, but I *think* that it will.I did too, but it doesn''t :( The only reason I tried variables is because tags aren''t visible (due to scoping?). It seems you can''t see tags (autotags or tags set explicitly with tag(''httpd'') defined in classes your class includes. This is a real problem from where I''m sat; it does make me wonder what tags are actually useful for. I suppose I could define the tag in the node, but that seems pretty redundant since I''m also including the ''httpd'' class.> Trevor > > Dick Davies wrote: >> I''m using a primitive template to build my iptables rulesets. >> It''s all in a branch on my github repo at >> >> http://github.com/rasputnik/babysteps-puppet/tree/templated-iptables >> >> template that looks like: >> >> <% if has_variable?(''httpd::open_firewall'') %> >> -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT >> <% end -%> >> >> (see http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/iptables/templates/iptables.erb >> ) >> >> i then set a variable in the httpd module like this: >> >> class httpd { >> $open_firewall = ''on'' >> #.... rest of httpd class def. >> } >> >> [ http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/httpd/manifests/init.pp >> ] >> >> The idea being that if a node has ''include httpd'', then when it runs >> ''include iptables'' >> it''ll open the right port. >> >> This works fine for classes that include httpd. The trouble is that i >> get this error on >> nodes that don''t : >> >> [root@node03 ~]# puppetd -tv >> info: Retrieving plugins >> err: Could not retrieve catalog: Failed to parse template >> iptables/iptables.erb: Class httpd has not been evaluated so its >> variables cannot be referenced at >> /etc/puppet/modules/iptables/manifests/init.pp:11 on node node03.pixie >> warning: Not using cache on failed catalog >> >> >> To my mind, that should be a warning, not an error. >> >> Is there any ''guard'' I can put in my template to stop this blowing up? >> >> I did try: >> >> <% if has_variable?(''httpd'') && has_variable?(''httpd::open_firewall'') %> >> >> but the first clause is always false, even on nodes that ''include httpd''. >> >> >> Sorry this has been a bit longwinded, but I''m a bit stumped here. >> Thanks in advance for >> any tips. >> >> > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkowedoACgkQyjMdFR1108Dh0gCfWz7tn6/5+K2w9LZK2P+ajsab > hy4An1ogD2dP3yj9wuGpn4v/Q1dKmoEa > =7UvV > -----END PGP SIGNATURE----- > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dick Davies
2009-Jun-11 11:20 UTC
[Puppet Users] Re: Any way to stop has_variable? throwing errors?
I''ve raised http://projects.reductivelabs.com/issues/2336 against this. To my mind, has_variable?(''panda::blood'') returning false makes more sense than throwing a parse error :) On Thu, Jun 11, 2009 at 10:42 AM, Dick Davies<rasputnik@hellooperator.net> wrote:> Hi Trevor, thanks for the idea. > > On Thu, Jun 11, 2009 at 4:28 AM, Trevor Vaughan<peiriannydd@gmail.com> wrote: > >> Someone might give you a better answer, but try: >> >> <% if tags.index(''httpd'') && has_variable?(''httpd::open_firewall'') %> >> >> This *may not* work due to file parsing order, but I *think* that it will. > > I did too, but it doesn''t :( > > The only reason I tried variables is because tags aren''t visible > (due to scoping?). > > It seems you can''t see tags (autotags or tags set explicitly with > tag(''httpd'') defined in > classes your class includes. > > This is a real problem from where I''m sat; it does make me wonder what > tags are actually > useful for. > > I suppose I could define the tag in the node, but that seems pretty > redundant since I''m > also including the ''httpd'' class. > > > > > >> Trevor >> >> Dick Davies wrote: >>> I''m using a primitive template to build my iptables rulesets. >>> It''s all in a branch on my github repo at >>> >>> http://github.com/rasputnik/babysteps-puppet/tree/templated-iptables >>> >>> template that looks like: >>> >>> <% if has_variable?(''httpd::open_firewall'') %> >>> -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT >>> <% end -%> >>> >>> (see http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/iptables/templates/iptables.erb >>> ) >>> >>> i then set a variable in the httpd module like this: >>> >>> class httpd { >>> $open_firewall = ''on'' >>> #.... rest of httpd class def. >>> } >>> >>> [ http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/httpd/manifests/init.pp >>> ] >>> >>> The idea being that if a node has ''include httpd'', then when it runs >>> ''include iptables'' >>> it''ll open the right port. >>> >>> This works fine for classes that include httpd. The trouble is that i >>> get this error on >>> nodes that don''t : >>> >>> [root@node03 ~]# puppetd -tv >>> info: Retrieving plugins >>> err: Could not retrieve catalog: Failed to parse template >>> iptables/iptables.erb: Class httpd has not been evaluated so its >>> variables cannot be referenced at >>> /etc/puppet/modules/iptables/manifests/init.pp:11 on node node03.pixie >>> warning: Not using cache on failed catalog >>> >>> >>> To my mind, that should be a warning, not an error. >>> >>> Is there any ''guard'' I can put in my template to stop this blowing up? >>> >>> I did try: >>> >>> <% if has_variable?(''httpd'') && has_variable?(''httpd::open_firewall'') %> >>> >>> but the first clause is always false, even on nodes that ''include httpd''. >>> >>> >>> Sorry this has been a bit longwinded, but I''m a bit stumped here. >>> Thanks in advance for >>> any tips. >>> >>> > >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.9 (GNU/Linux) >> >> iEYEARECAAYFAkowedoACgkQyjMdFR1108Dh0gCfWz7tn6/5+K2w9LZK2P+ajsab >> hy4An1ogD2dP3yj9wuGpn4v/Q1dKmoEa >> =7UvV >> -----END PGP SIGNATURE----- >> >> >> >> >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Trevor Vaughan
2009-Jun-11 11:35 UTC
[Puppet Users] Re: Any way to stop has_variable? throwing errors?
One other try: <% if classes.index(''httpd'') .... I forgot that tags weren''t exposed in the ERB. Trevor On Thu, Jun 11, 2009 at 05:42, Dick Davies<rasputnik@hellooperator.net> wrote:> > Hi Trevor, thanks for the idea. > > On Thu, Jun 11, 2009 at 4:28 AM, Trevor Vaughan<peiriannydd@gmail.com> wrote: > >> Someone might give you a better answer, but try: >> >> <% if tags.index(''httpd'') && has_variable?(''httpd::open_firewall'') %> >> >> This *may not* work due to file parsing order, but I *think* that it will. > > I did too, but it doesn''t :( > > The only reason I tried variables is because tags aren''t visible > (due to scoping?). > > It seems you can''t see tags (autotags or tags set explicitly with > tag(''httpd'') defined in > classes your class includes. > > This is a real problem from where I''m sat; it does make me wonder what > tags are actually > useful for. > > I suppose I could define the tag in the node, but that seems pretty > redundant since I''m > also including the ''httpd'' class. > > > > > >> Trevor >> >> Dick Davies wrote: >>> I''m using a primitive template to build my iptables rulesets. >>> It''s all in a branch on my github repo at >>> >>> http://github.com/rasputnik/babysteps-puppet/tree/templated-iptables >>> >>> template that looks like: >>> >>> <% if has_variable?(''httpd::open_firewall'') %> >>> -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT >>> <% end -%> >>> >>> (see http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/iptables/templates/iptables.erb >>> ) >>> >>> i then set a variable in the httpd module like this: >>> >>> class httpd { >>> $open_firewall = ''on'' >>> #.... rest of httpd class def. >>> } >>> >>> [ http://github.com/rasputnik/babysteps-puppet/blob/templated-iptables/modules/httpd/manifests/init.pp >>> ] >>> >>> The idea being that if a node has ''include httpd'', then when it runs >>> ''include iptables'' >>> it''ll open the right port. >>> >>> This works fine for classes that include httpd. The trouble is that i >>> get this error on >>> nodes that don''t : >>> >>> [root@node03 ~]# puppetd -tv >>> info: Retrieving plugins >>> err: Could not retrieve catalog: Failed to parse template >>> iptables/iptables.erb: Class httpd has not been evaluated so its >>> variables cannot be referenced at >>> /etc/puppet/modules/iptables/manifests/init.pp:11 on node node03.pixie >>> warning: Not using cache on failed catalog >>> >>> >>> To my mind, that should be a warning, not an error. >>> >>> Is there any ''guard'' I can put in my template to stop this blowing up? >>> >>> I did try: >>> >>> <% if has_variable?(''httpd'') && has_variable?(''httpd::open_firewall'') %> >>> >>> but the first clause is always false, even on nodes that ''include httpd''. >>> >>> >>> Sorry this has been a bit longwinded, but I''m a bit stumped here. >>> Thanks in advance for >>> any tips. >>> >>> > >> -----BEGIN PGP SIGNATURE----- >> Version: GnuPG v1.4.9 (GNU/Linux) >> >> iEYEARECAAYFAkowedoACgkQyjMdFR1108Dh0gCfWz7tn6/5+K2w9LZK2P+ajsab >> hy4An1ogD2dP3yj9wuGpn4v/Q1dKmoEa >> =7UvV >> -----END PGP SIGNATURE----- >> >> > >> > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---