On 13 March 2011 05:00, Mohamed Lrhazi <lrh...@gmail.com> wrote:
> I have a var defined like this:
>
> $uiso_scanners = [
>    ["uiso-scanner.example.com","192.168.151.21"],
>    ["uiso-scanner1.example.com","192.168.18.37"],
>    ]
>
> and then in a template I have:
>
> <% if uiso_scanners -%>
> # Allow communication with UISO scanners
> <% uiso_scanners.each do |uiso_scanner| -%>
> -A RH-Firewall-1-INPUT -s <%= uiso_scanner[1] %> -j ACCEPT
> <% end -%>
> <% end -%>
>
> Instead of the IP addresses, this ends up with some weird number
> printed, 105 and 52!

This is because that nested array flattens out during the compile
phase (I think) to

$uiso_scanners = [
    "uiso-scanner.example.com","192.168.151.21",
    "uiso-scanner1.example.com","192.168.18.37",
 ]

If you try setting the above $uis_scanners, you'll get the similar result.
(Try instrumenting your .erb like:

<% if uiso_scanners -%>
# Allow communication with UISO scanners
<% uiso_scanners.each do |uiso_scanner| -%>
-A RH-Firewall-1-INPUT -s <%= p uiso_scanner; puts; uiso_scanner[1]
%> -j ACCEPT
<% end -%>
<% end -%>

and observe)

> If I change the var definition to be:
>
> $uiso_scanner1=["uiso-scanner.example.com","192.168.151.21"]
> $uiso_scanner2=["uiso-scanner1.example.com","192.168.18.37"]
> $uiso_scanners = [$uiso_scanner1,$uiso_scanner2]
>
> The template works as expected.
>
> What's the problem with the first style?

I'm not sure why the above form doesn't flatten out like in the first case.

You could try a hash like this if you prefer the visual appeal:

$uiso_scanners = {
         "uiso-scanner.example.com" => "192.168.151.21",
         "uiso-scanner1.example.com" => "192.168.18.37",
}

<% if uiso_scanners -%>
# Allow communication with UISO scanners
<% uiso_scanners.keys.each do |host| -%>
-A RH-Firewall-1-INPUT -s <%= uiso_scanners[host]  %> -j ACCEPT
<% end -%>
<% end -%>


-Naresh V.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to