David Kramer
2011-Feb-16 08:52 UTC
[Puppet Users] error using If/Else conditionals inside templates
I am running Puppet 2.6.4, and have run into a situation where I would like to use conditional statements inside a template ERB file. I am trying to deploy apache virtual host configuration files, and have found that certain environments use SSL certificate files from one vendor and other environments use different formatted certificates from another vendor. I would like to avoid maintaining two versions of virtual host files and would prefer to use a single template file with conditional logic using tags to decide which lines to use. When I test the syntax of the Template I get Syntax OK. When I try to run the run the catalog I get the following error: puppet-agent[6010]: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse template foobar/vhost.conf.erb: Could not find value for ''development'' at /etc/puppet/modules/foobar/manifests/vhost-conf.pp:6 on node www.example.com Here is the snippet from my vhost.erb ..... Alias /js /var/www/html/<%= hostname %>/static/js Alias /video /var/www/html/<%= hostname %>/static/video Alias /pdf /var/www/html/<%= hostname %>/static/pdf SSLEngine on <% if tagged(development) %> SSLCertificateFile /etc/pki/tls/certs/<%= hostname %>.pem SSLCertificateKeyFile /etc/pki/tls/certs/<%= hostname %>.pem <% else tagged(testing) %> SSLCertificateFile /etc/pki/tls/certs/<%= hostname %>.crt SSLCertificateKeyFile /etc/pki/tls/private/<%= hostname %>.key SSLCertificateChainFile /etc/pki/tls/certs/<%= hostname %>_bundle.crt <% end %> </VirtualHost> Any thoughts would be greatly appreciated. Also is it possible to use if else statements as well? Cheers, DK -- 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.
Ben Hughes
2011-Feb-16 23:33 UTC
Re: [Puppet Users] error using If/Else conditionals inside templates
On Wed, Feb 16, 2011 at 12:52:49AM -0800, David Kramer wrote:> <% if tagged(development) %>In ERB the syntax is different I believe. The tagged() is in manifest syntax. In ERB land, you have access to tags via: <% tags.each do |tag| -%> So perhaps something like <% if tags.include?( "development" ) %> See http://docs.puppetlabs.com/guides/templating.html "Access to defined tags and classes" -- ben -- 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.