There's a problem with either your data structure or your logic, or both. I am not sure I have enough here to sort out which.
The first issue I see is your hiera()
lookup function cannot lookup the nest ip
hash directly. Your Hiera key is just iptables::test
. You can get the full value of that via lookup and parse it further if needed.
$variable1 = hiera('iptables::test')
If you don't need the nested ip
hash, your inline_template()
works as written. Your data structure would just be a single hash.
---
iptables::test:
1.1.1.1: adm-1
2.2.2.2: adm-2
3.3.3.3: adm-3
If you need the nested hash, then you need a nested loop.
$variable2 = inline_template("<% @variable1.keys.each do |ip| %><% @variable1[ip].each do |key, value| %>Allow From <%= key %> #<%= value %>\n<% end %><% end %>")
Putting it together to demonstrate:
$ cat test.pp
$variable1 = {
ip => {
'1.1.1.1' => 'adm-1',
'2.2.2.2' => 'adm-2',
'3.3.3.3' => 'adm-3',
},
}
$variable2 = inline_template("<% @variable1.keys.each do |ip| %><% @variable1[ip].each do |key, value| %>Allow From <%= key %> #<%= value %>\n<% end %><% end %>")
notice($variable2)
$ puppet apply test.pp
...
Notice: Scope(Class[main]): Allow From 1.1.1.1 #adm-1
Allow From 2.2.2.2 #adm-2
Allow From 3.3.3.3 #adm-3
Notice: Compiled catalog for localhost in environment production in 0.02 seconds
Notice: Applied catalog in 0.01 seconds
My test here did not use Hiera, because Hiera is just a way to bring data from outside of a Puppet class. I wanted to demonstrate this way because it will be easier for you to isolate your problem.