Just be careful how you call the variables: puppet var is <%= @name%>,
local var will be <%= name %>


On Sat, Jul 26, 2014 at 6:42 AM, senorsmile <senorsm...@gmail.com> wrote:

> Ah, I didn't know you could do that.  Reading through the documentation
> can lead to one's mind melting.
>
> This may be preferable as create_resources messes up my resource ordering.
>
>
>
> Thanks!
>
> On Friday, July 25, 2014 8:40:27 PM UTC-7, Cristian Falcas wrote:
>
>> I think you can solve like this also:
>>
>> <% @clusters.each do |key,value| %>
>> cluster name is <%=key %> and cluster port is <%= value %>
>> <% end -%>
>>
>>
>>
>>
>> On Fri, Jul 25, 2014 at 8:56 PM, senorsmile <senor...@gmail.com> wrote:
>>
>>>  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 puppet-users...@googlegroups.com.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/puppet-users/e0ef2668-931e-419d-916a-9541beb2ef68%
>>> 40googlegroups.com
>>> <https://groups.google.com/d/msgid/puppet-users/e0ef2668-931e-419d-916a-9541beb2ef68%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/93631c84-b157-4e06-bed5-8e82a374a137%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-users/93631c84-b157-4e06-bed5-8e82a374a137%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAMo7R_cpKeXk9CRJnu7r0GPJytULkD%3DQGG4L1a-Yv_op8N3oRA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to