I have solved this using create_resources
http://docs.puppetlabs.com/references/latest/function.html#createresources
which converts the hash into arrays that a define can digest.
On Friday, July 25, 2014 10:27:21 AM UTC-7, senorsmile wrote:
>
> So, I have this partially working.
>
> in /etc/puppet/manifests/nodes.pp I have (all entries truncated and
> scrubbed):
>
> node node_example {
> class { 'ganglia::install::gmetad':
> clusters => [
> 'cluster1',
> 'cluster2',
> 'cluster3',
> 'cluster4',
> ]
> }
>
>
> and under /etc/puppet/modules/ganglia/install/gmetad.pp
>
> class ganglia::install::gmetad () {
>
>
> define generate_gmond_init(
> $init_template = 'ganglia/gmond_init.erb',
> $conf_template = 'ganglia/gmond_master_conf.erb',
> ) {
> file { "/etc/init/gmond_${name}.conf":
> content => template("$init_template"),
> }
> file { "/etc/ganglia/gmond_${name}.conf":
> content => template("$conf_template"),
> }
> }
>
>
> generate_gmond_init{ $clusters: }
>
>
>
> }
>
>
> Now, in each template I can call
> <%= name %>
> in order to call the name var as it passes through each array.
>
>
>
> I need to make this a little more complicated by adding more than a single
> bit of information; i.e. I need to create a hash of clusters, each with
> their own data, something like this:
>
> clusters => {
> 'cluster1' => { port => 8655 },
> 'cluster2' => { port => 8656 },
> 'cluster3' => { port => 8657 },
> 'cluster4' => { port => 8658 },
> }
>
> so that I can access more than just the cluster name in each template.
>
>
> On Friday, July 25, 2014 6:56:57 AM UTC-7, Yanis Guenane wrote:
>>
>>
>>
>> On 07/24/2014 08:08 PM, senorsmile wrote:
>> > For example, I have an array like this:
>> >
>> > clusters => [
>> > 'cluster1',
>> > 'cluster2',
>> > 'cluster3',
>> > 'cluster4',
>> > ]
>> >
>> >
>> >
>> > I then have a cluster.init.erb that looks soemthing like this:
>> >
>> > start on runlevel [2345]
>> > stop on runlevel [!2345]
>> >
>> > expect fork
>> > respawn
>> >
>> > <% @clusters.each do | cluster | -%>
>> > env PIDFILE="/var/run/${cluster}.pid"
>> >
>> > exec /usr/sbin/program_name --pid-file=$PIDFILE
>> > <% end -%>
>> >
>> >
>> > That is all theoretical at this point since it doesn't work.
>> > What I need it to do is dynamically generate a certain number of files,
>> > equal to the number of files in the array "clusters", whose names I
>> will
>> > not know beforehand, and changes from host to host.
>> >
>>
>> You could create a define that would be an intermediate layer. Code
>> would look like the following :
>>
>> Manifest
>> --------
>>
>> $clusters = ['cluster1', 'cluster2', 'clustern']
>>
>> myclass::mydefine {$clusters : }
>>
>>
>> Define
>> ------
>>
>> class myclass::mydefine {
>>
>> $path = "/tmp/${name}"
>>
>> file { $path :
>> ensure => present,
>> content => template('myclass/foo.erb'),
>> }
>>
>> }
>>
>> Template
>> --------
>>
>> Find my value <%= @name %>
>>
>>
>> Hope this helps,
>>
>> --
>> Yanis Guenane
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/e0ef2668-931e-419d-916a-9541beb2ef68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.