On Aug 25, 11:19 pm, "Matt Delves" <m.del...@ballarat.edu.au>
wrote:> Hey Folks,
> I''ve run into a bit of a snag in setting up the manifests. What I
want
> to do is use an array of hashes as variables in a template.
>
> An extract of node is:
> --
> $security_access = [{:type => "+", :group =>
"allowdpeople" :rule =>
> "ALL"}, {:type => "-", :group =>
"disallowedpeople", :rule => "ALL"}]
As far as I am aware, hashes are not a feature of the Puppet
language. (Do not be confused by Puppet''s close relationship with
Ruby: the Puppet manifest language is *not* Ruby, superficial
similarities notwithstanding.)
>
> $allow_groups = "allowedpeople"
>
> file {
> "/tmp/access.conf":
> owner => root,
> group => root,
> mode => 0644,
> content => template("access.conf.erb");
>
> "/tmp/sshd_config":
> owner => root,
> group => root,
> mode => 0644,
> content => template("sshd_config.erb");
> }
> --
>
> An extract of the template is:
> --
> <% security_access.each do | access | %>
> <%=access[:type]%>:<%=access[:group]%>:<%=access[:rule]%>
> <% end %>
> --
>
> What ends up happening is that Puppet complains of syntax errors.
Disclaimer: I''m not fully up to speed on templating.
I see three potential solutions:
1) Flatten and split your array of hashes into two or more plain
arrays, something like this:
$allowed_people = [''+'', ''allowedgroup'',
''ALL'']
$denied_people = [''-'', ''deniedgroup'',
''ALL'']
This should work reasonably well as long as you can determine in
advance which variables your template will use.
2) It may also be possible to use nested arrays (i.e. just convert
your hashes into ordinary arrays), but I''m uncertain whether Puppet
supports them.
3) For a more structured approach, you might be able to use Puppet
classes instead of hashes: it appears that the templating engine
supports discovering classes and retrieving their variables. For
instance,
class access::allowed {
$type = ''+''
$group = ''allowedpeople''
$rule = ''ALL''
}
[...]
In your template you would iterate over the ''classes'' array,
select
those whose names begin with "access::", and use scope.lookupvar() to
retrieve each of the needed variables. I don''t think the template
would need to be too much more complicated than your current version.
You may need to tinker a bit to figure out how to make this work, but
if it does work then it will be both powerful and flexible.
Good luck.
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/puppet-users?hl=en
-~----------~----~----~----~------~----~------~--~---