From 5829559aca9c80c1d72c7ed571d6d4d2548587cb Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Wed, 12 Mar 2014 19:06:47 +1100 Subject: [PATCH] add hash/array support for upstream_cfg_prepend --- spec/defines/resource_upstream_spec.rb | 8 ++++++++ templates/conf.d/upstream.erb | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/defines/resource_upstream_spec.rb b/spec/defines/resource_upstream_spec.rb index a2290e3d7..8423eb437 100644 --- a/spec/defines/resource_upstream_spec.rb +++ b/spec/defines/resource_upstream_spec.rb @@ -36,11 +36,19 @@ 'test3' => 'test value 3', 'test1' => 'test value 1', 'test2' => 'test value 2', + 'test4' => ['test value 1', 'test value 2'], + 'test5' => {'subkey1' => 'subvalue1'}, + 'test6' => {'subkey1' => ['subvalue1', 'subvalue2']}, }, :match => [ ' test1 test value 1;', ' test2 test value 2;', ' test3 test value 3;', + ' test4 test value 1;', + ' test4 test value 2;', + ' test5 subkey1 subvalue1;', + ' test6 subkey1 subvalue1;', + ' test6 subkey1 subvalue2;', ], }, { diff --git a/templates/conf.d/upstream.erb b/templates/conf.d/upstream.erb index 5da66ab20..a96121ab2 100644 --- a/templates/conf.d/upstream.erb +++ b/templates/conf.d/upstream.erb @@ -1,6 +1,14 @@ upstream <%= @name %> { <% if @upstream_cfg_prepend -%><% @upstream_cfg_prepend.sort_by{|k,v| k}.each do |key,value| %> - <%= key %> <%= value %>; +<% if value.is_a?(Hash) -%><% value.each do |subkey,subvalue| -%> +<% Array(subvalue).each do |asubvalue| -%> + <%= key %> <%= subkey %> <%= asubvalue %>; +<% end -%> +<% end -%><% else -%> +<% Array(value).each do |asubvalue| -%> + <%= key %> <%= asubvalue %>; +<% end -%> +<% end -%> <% end -%><% end -%> <% @members.each do |i| %> server <%= i %> fail_timeout=<%= @upstream_fail_timeout %>;<% end %>