About | FAQ | Help
Ask Your Question
0

how to define multiple array on hiera.yaml file and how we can iterate/access in template file(erb file)

asked 2014-04-04 09:21:07 -0500

rasati gravatar image

updated 2018-02-04 04:07:46 -0500

Henrik Lindberg gravatar image

hiera.yaml file entry

project:module:propertyName:: servers:
-server1 
 ip:
port:
route:
hostname:
-member1;{name, server, ip}
-member2:{name, server, ip}

-server2 
 ip:
port:
route:
hostname:
-member1;{name, server, ip}
-member2:{name, server, ip}

xyz.erb file here how we can access that hiera proprty.

Please also let me know how i can define in hiera as well as in erb file for multiple array values.

Thanks

edit retag flag offensive close merge delete

Comments

Hi, please put your YAML in code blocks because it is not readable like this. How should the erb template render the array values? One value per line, all on ...(more)

ffrank gravatar imageffrank ( 2014-04-04 16:42:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-02-16 03:13:07 -0500

Hypnoz gravatar image

Here's something that may help. Try this in hiera:

mymodule::hostlist: >-
    "hostname001.example.com:5046", "hostname002.example.com:5046", "hostname003.example.com:5046"

Then put this in your erb template:

<%= scope.function_hiera(['mymodule::hostlist']) -%>



Another option that may match closer to the type of Hiera syntax you're using above would be like this:

module/init.pp:

$myarray = hiera('mymodule::servers')

then in the ERB:

<% @myarray.each do |server| -%>
<%= server['port'] %>
<%= server['route'] %>
<% end -%>
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-04-04 09:21:07 -0500

Seen: 498 times

Last updated: Feb 16