erb if condition inside each.do loop

157 views
Skip to first unread message

João Matos

unread,
Jul 17, 2017, 5:28:58 AM7/17/17
to Puppet Users
Hi all

this isnt working . I dont know why. Can you help please?

message
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Internal Server Error: org.jruby.exceptions.RaiseException: (SyntaxError) /etc/puppetlabs/code/environments/teg17_uat/modules/apache/templates/confd/workers.properties.erb:14: syntax error, unexpected end-of-file
_erbout.force_encoding(__ENCODING__)



puppet code:
if $worker_list != undef {
        file { 'workers.properties':
          ensure  => file,
          path    => "${::apache::conf_dir}/workers.properties",
          mode    => $::apache::file_mode,
          content => template('apache/confd/workers.properties.erb'),
          notify  => Class['apache::service'],
        }
      }



template
#workers
worker.list=<%= @worker_list.sort_by {|key, v| key}.map{|key, v| key}.join(',') -%>

<% @worker_list.each do |name, content| -%>
worker.<%= name %>.type=<%= content['type'] %>
worker.<%= name %>.port=<%= content['port'] %>
worker.<%= name %>.host=<%= content['host'] %>
worker.<%= name %>.socket_keepalive=<%= content['socket_keepalive'] %>
worker.<%= name %>.ping_mode=<%= content['ping_mode'] %>
<% if @lbfactor -%>worker.<%= name %>.lbfactor=<%= content['lbfactor'] %><% end %>
<% if @balanced_workers -%>worker.<%= name %>.balanced_workers=<%= content['balanced_workers'] %><% end %>
<% if @sticky_session -%>worker.<%= name %>.sticky_session=<%= content['sticky_session'] %><% end %>
<% end -%>


eg data from hiera:
cncblaspringfield:
        type: ajp13
        port: 8017
        host: vlspringfield.com
        socket_keepalive: true
        ping_mode: A
        ping_timeout: 60000
        lbfactor: 1
    cncdbla_loadbalancer:
        type: lb
        balanced_workers: "cncbla_dover,cncblaspringfield"
        sticky_session: 1

Note: the idea is to apply the last 3 only if the last 3 variables (lbfactor , etc) have content.

Tks in advance! 

João Matos

unread,
Jul 25, 2017, 10:59:25 AM7/25/17
to Puppet Users
if anyone needs , managed to do it like this

<% @worker_list.each do |name, content| -%>
<% if (content['type']) %>worker.<%= name %>.type=<%= content['type'] %><% end %>
<% if (content['port']) %>worker.<%= name %>.port=<%= content['port'] %><% end %>
<% if (content['host']) %>worker.<%= name %>.host=<%= content['host'] %><% end %>
<% if (content['socket_keepalive']) %>worker.<%= name %>.socket_keepalive=<%= content['socket_keepalive'] %><% end %>
<% if (content['ping_mode']) %>worker.<%= name %>.ping_mode=<%= content['ping_mode'] %><% end %>
<% if (content['ping_timeout']) %>worker.<%= name %>.ping_timeout=<%= content['ping_timeout'] %><% end %>
<% if (content['lbfactor']) %>worker.<%= name %>.lbfactor=<%= content['lbfactor'] %><% end %>
<% if (content['balanced_workers']) %>worker.<%= name %>.balanced_workers=<%= content['balanced_workers'] %><% end %>
<% if (content['sticky_session']) %>worker.<%= name %>.sticky_session=<%= content['sticky_session'] %><% end %>

<% end -%>
Reply all
Reply to author
Forward
0 new messages