Hi,
I am stuck on this task. I need to generate a file with this content:
...
/bin/mount --bind /home/some/path/ /home/someuser/www
/bin/mount --bind /home/comple/tely/different/path/ /home/differentuser/www
/bin/mount --bind /home/another/path/ /home/anotheruser/www
.
.
...
For each row I need to insert two variables.
I am able to construct simple loop in erb file, but this does not solve my
problem:
<% userss.each do |user| -%>
/bin/mount --bind /some/path/<%= user %> /home/somepath/<%=
user %>
<% end -%>
I need loop, whose content looks like this:
/bin/mount --bind /some/path/<%= path %> /home/somepath/<%= user %>
Can someone point me in right direction?
Thanks.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/AyvMd9vq4EAJ.
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.
Is @path supposed to be the same for each user? If so, you can just put
that variable in the block.
<% @users.each do |user| %>
/bin/mount --bind <%= @path %> /home/<%= user %>
<% end %>
If each user has a path value unique to them, you might want to put that in
an array of hashes and then iterate over that like this:
(in Puppet class)
$users = [ { name => ''alice'', path =>
''/alice/path'' }, { name => ''bob'',
path => ''/bob/path'' } ]
(in template)
<% @users.each do |user| %>
/bin/mount --bind <%= user[''path''] %> /home/<%=
user[''name''] %>
<% end %>
On Friday, July 27, 2012 1:12:48 AM UTC-7, Jiří Červenka
wrote:>
> Hi,
> I am stuck on this task. I need to generate a file with this content:
> ...
> /bin/mount --bind /home/some/path/ /home/someuser/www
> /bin/mount --bind /home/comple/tely/different/path/ /home/differentuser/www
> /bin/mount --bind /home/another/path/ /home/anotheruser/www
> .
> .
> ...
>
> For each row I need to insert two variables.
>
> I am able to construct simple loop in erb file, but this does not solve my
> problem:
>
> <% userss.each do |user| -%>
> /bin/mount --bind /some/path/<%= user %>
/home/somepath/<%= user %>
> <% end -%>
>
> I need loop, whose content looks like this:
>
> /bin/mount --bind /some/path/<%= path %> /home/somepath/<%= user
%>
>
> Can someone point me in right direction?
>
> Thanks.
>
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/puppet-users/-/Lbq0wX5imhoJ.
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.
Jochen Schalanda
2012-Jul-27 09:05 UTC
Re: [Puppet Users] Loop with two variables in puppet
Hi Jiří,
you could use a simple hash to get the result you want. Using
Hash.each_pair [1] you can iterate over the keys and values in your hash
representing the mount points.
Example:
your_manifest.pp:
$mountpoints = { ''user1'' =>
''/home/some/path'', ''user2'' =>
/home/another/path'' }
your_template.erb:
<% mountpoints.each do |user, path| -%>
/bin/mount --bind <%= path %> /home/<%= user %>/www
<% end -%>
[1]: http://www.ruby-doc.org/core-1.9.3/Hash.html#method-i-each_pair
Best regards,
Jochen
On 27.07.2012 10:12, Jiří Červenka wrote:> Hi,
> I am stuck on this task. I need to generate a file with this content:
> ...
> /bin/mount --bind /home/some/path/ /home/someuser/www
> /bin/mount --bind /home/comple/tely/different/path/ /home/differentuser/www
> /bin/mount --bind /home/another/path/ /home/anotheruser/www
> .
> .
> ...
>
> For each row I need to insert two variables.
>
> I am able to construct simple loop in erb file, but this does not solve
> my problem:
>
> <% userss.each do |user| -%>
> /bin/mount --bind /some/path/<%= user %>
/home/somepath/<%= user %>
> <% end -%>
>
> I need loop, whose content looks like this:
>
> /bin/mount --bind /some/path/<%= path %> /home/somepath/<%= user
%>
>
> Can someone point me in right direction?
>
> Thanks.
--
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.
Unless you want to establish a proper data structure (array of pairs), I''d suggest Array#zip: http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-zip Best Regards, D. On 27.07.2012 10:12, Jiří Červenka wrote:> Hi, > I am stuck on this task. I need to generate a file with this content: > ... > /bin/mount --bind /home/some/path/ /home/someuser/www > /bin/mount --bind /home/comple/tely/different/path/ /home/differentuser/www > /bin/mount --bind /home/another/path/ /home/anotheruser/www > . > . > ... > > For each row I need to insert two variables. > > I am able to construct simple loop in erb file, but this does not solve > my problem: > > <% userss.each do |user| -%> > /bin/mount --bind /some/path/<%= user %> /home/somepath/<%= user %> > <% end -%> > > I need loop, whose content looks like this: > > /bin/mount --bind /some/path/<%= path %> /home/somepath/<%= user %> > > Can someone point me in right direction? > > Thanks. > > -- > You received this message because you are subscribed to the Google > Groups "Puppet Users" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/puppet-users/-/AyvMd9vq4EAJ. > 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.-- 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.