Puppet erb template create loop

269 views
Skip to first unread message

Rafael Tomelin

unread,
Feb 14, 2017, 12:22:52 PM2/14/17
to Puppet Users
Hi dear,

I is create a module and need loop in puppet class and template


The my class step is:
1) My class have array declared;
$pools = [
    {
      name               => 'PoolDiario',
      poolType           => 'Backup',
      recycle            => 'yes',
      autoPrune          => 'yes',
      volumeRetention    => '30 days',
      maximumVolumeBytes => '1G',
      maximumVolumes     => '100',
      labelFormat        => 'Local-'
    }
    ,
    {
      name               => 'PoolDiario2',
      poolType           => 'Backup2',
      recycle            => 'yes',
      autoPrune          => 'yes',
      volumeRetention    => '20 days',
      maximumVolumeBytes => '5G',
      maximumVolumes     => '10',
      labelFormat        => 'Local2'
    }
    ]) 

2) The array is create file;
example:

count array$pools

  $teste = $pools[COUNT]['name']

#LOOP
  file { "/etc/bacula/pool/pool_$teste.conf":
    ensure  => 'file',
    owner   => 'bacula',
    group   => 'bacula',
    content => template('bacula/director/pool_conf.erb')
  }


3) Template loop get array.
Pool {
<% pools.each do |pool| -%>
  Name = "<%= pool['name'] %>"
  Pool Type = "<%= pool['poolType'] %>"
  Recycle = <%= pool['recycle'] %>
  AutoPrune = <%= pool['autoPrune'] %>
  Volume Retention = "<%= pool['volumeRetention'] %>"
  Maximum Volume Bytes = "<%= pool['maximumVolumeBytes'] %>" 
  Maximum Volumes = <%= pool['maximumVolumes'] %>
  Label Format = "<%= pool['labelFormat'] %>"

<% end -%>
}


But this create Pool to array.

I can make this module?


Henrik Lindberg

unread,
Feb 16, 2017, 3:09:38 PM2/16/17
to puppet...@googlegroups.com
Puppet 4.x (and puppet 3.x with future parser) supports iteration with
functions such as each, map, reduce (and many more). That should enable
you to do what you want.

- henrik

>
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to puppet-users...@googlegroups.com
> <mailto:puppet-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/b76ca740-d7f6-4dd6-8079-43bc72700c06%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/b76ca740-d7f6-4dd6-8079-43bc72700c06%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

Rafael Tomelin

unread,
Feb 17, 2017, 6:03:41 PM2/17/17
to puppet...@googlegroups.com
Hi dear,

Very thanks!

To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/0554267c-29cc-5bda-a6b2-2df9f1c9dc82%40puppet.com.

For more options, visit https://groups.google.com/d/optout.
--
Atenciosamente,
Rafael Tomelin
skype: rafael.tomelin

RHCE - Red Hat Certified Engineer
Zabbix - ZABBIX Certified Specialist
LPI3 
ITIL v3

Reply all
Reply to author
Forward
0 new messages