error with yaml and nested array hiera

asked 2017-09-29 08:37:02 -0500

Ashc gravatar image

Hi, we have the following defined type:

define apache::redirdomains(
                     $httpport = "80",
                    $domains = [],){
 file{'/etc/httpd/conf.d' :
     ensure => 'file',
     content => template("apache/redirect_domains.erb"),
   }
}

erb snippit:

<%- @domains.each do |domain,value|  -%>
 <%- domain.each do |key,val| -%>
  ServerAlias <%=val['domain'] %>
  RewriteCond %{HTTP_HOST} ^<%=val['domain'] %>
  RewriteRule ^(.*)$ <%=val['to'] %>[R=301,L] 
<%- end -%> <%- end -%>

YAML:

domains:
  - domain:
       domain: 'www.example.com'
       to: 'https://www.test.com/example'
  - domain2:
       domain: 'example.com'
       to: 'https://www.test.com/example'

In the default.pp: < createresources(::apache::redirdomains, hierahash('apache::redirdomains'))

But we get the following error

" Error: Evaluation Error: Error while evaluating a Function Call, no implicit conversion of Array into Hash"

if I use site.pp file and enter the value domains => [{domain => {domain => 'domain1.com', to => 'wwww.test1.com'}},{domain => {domain=>'domain2.com',to => 'www.test2.com'}}]

it works fine

any help will be appreciated.

edit retag flag offensive close merge delete