Christopher Wood
2011-Sep-21 19:00 UTC
[Puppet Users] deliberately causing template failure?
How do I cause template failure in the erb ruby? I''d like the same kind of failure as for a template syntax issue, where puppet keeps going. I know I can use "exit" in a template, but I haven''t yet tested if that will simply cause my puppet agent to exit altogether. Background: I''m trying to template /etc/network/interfaces on Debian/Ubuntu, so of course there can be many different interfaces, but each one must have certain values (like ip address). I want it so that if a value in the data hash is missing then I can cause the template, and thus the file declaration to fail. That will save us from incorrect data entry when defining interfaces. As an example, I''d like something like the following, but if the nil caused the file to not be created, rather than created with the "this file is " portion as follows: # cat /etc/puppet/templates/xx.erb this file is <%= if xx.has_key?(''zz'') xx[''zz''] else nil end %> # cat /tmp/xx.pp $xx = { yy => ''aa'', qq => ''bb'' } file { ''/tmp/xx.txt'': content => template(''xx.erb''), } # puppet apply /tmp/xx.pp notice: /Stage[main]//File[/tmp/xx.txt]/ensure: defined content as ''{md5}7433a07924aa1785f0c567cc7c5aedfb'' # cat /tmp/xx.txt this file is # -- 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.
Daniel Pittman
2011-Sep-21 19:56 UTC
Re: [Puppet Users] deliberately causing template failure?
On Wed, Sep 21, 2011 at 12:00, Christopher Wood <christopher_wood@pobox.com> wrote:> How do I cause template failure in the erb ruby? I''d like the same kind of failure as for a template syntax issue, where puppet keeps going. I know I can use "exit" in a template, but I haven''t yet tested if that will simply cause my puppet agent to exit altogether.I believe you should be able to `raise Puppet::Error, "your message here"` and have that fail in the way you desire. Daniel -- ⎋ Puppet Labs Developer – http://puppetlabs.com ♲ Made with 100 percent post-consumer electrons -- 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.
using the fail function should work: content = inline_template(''<%= fail("doh") %>'') On Wed, Sep 21, 2011 at 12:56 PM, Daniel Pittman <daniel@puppetlabs.com>wrote:> On Wed, Sep 21, 2011 at 12:00, Christopher Wood > <christopher_wood@pobox.com> wrote: > > How do I cause template failure in the erb ruby? I''d like the same kind > of failure as for a template syntax issue, where puppet keeps going. I know > I can use "exit" in a template, but I haven''t yet tested if that will simply > cause my puppet agent to exit altogether. > > I believe you should be able to `raise Puppet::Error, "your message > here"` and have that fail in the way you desire. > > Daniel > -- > ⎋ Puppet Labs Developer – http://puppetlabs.com > ♲ Made with 100 percent post-consumer electrons > > -- > 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. > >-- "Join us for PuppetConf <http://bit.ly/puppetconfsig>, September 22nd and 23rd in Portland, OR." <http://bit.ly/puppetconfsig> -- 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.
Christopher Wood
2011-Sep-21 20:05 UTC
Re: [Puppet Users] deliberately causing template failure?
Thank you to you and Daniel, both your methods do what I want. On Wed, Sep 21, 2011 at 12:58:38PM -0700, Dan Bode wrote:> using the fail function should work: > > content = inline_template(''<%= fail("doh") %>'') > > On Wed, Sep 21, 2011 at 12:56 PM, Daniel Pittman > <[1]daniel@puppetlabs.com> wrote: > > On Wed, Sep 21, 2011 at 12:00, Christopher Wood > <[2]christopher_wood@pobox.com> wrote: > > How do I cause template failure in the erb ruby? I''d like the same > kind of failure as for a template syntax issue, where puppet keeps > going. I know I can use "exit" in a template, but I haven''t yet tested > if that will simply cause my puppet agent to exit altogether. > > I believe you should be able to `raise Puppet::Error, "your message > here"` and have that fail in the way you desire. > > Daniel > -- > ⎋ Puppet Labs Developer – [3]http://puppetlabs.com > ♲ Made with 100 percent post-consumer electrons > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To post to this group, send email to [4]puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > [5]puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at > [6]http://groups.google.com/group/puppet-users?hl=en. > > -- > "Join us for [7]PuppetConf, September 22nd and 23rd in Portland, OR." > > -- > 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. > > References > > Visible links > 1. mailto:daniel@puppetlabs.com > 2. mailto:christopher_wood@pobox.com > 3. http://puppetlabs.com/ > 4. mailto:puppet-users@googlegroups.com > 5. mailto:puppet-users%2Bunsubscribe@googlegroups.com > 6. http://groups.google.com/group/puppet-users?hl=en > 7. http://bit.ly/puppetconfsig-- 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.