Jonathan Gazeley | 10 Jul 2012 11:21
Picon
Picon
Favicon

[Puppet Users] Array mapping

Hi all,

I'm aware that using a "define" can be used to create multiple resources 
from a list of items, like this:

define print {
    notify{"the message is: ${name}": }
}

print{["one", "two", "three"]: }

This would be the same as making these resources by hand:

notify{"the message is: one": }
notify{"the message is: two": }
notify{"the message is: three": }

Some of my facter variables are formatted as a comma-separated list of 
network interfaces, and of system disks. I wish to create separate 
Nagios checks for each. When I reference the variable like this, the 
individual entries from the list are not treated as an array, but as a 
concatenated string.

notify{ [$diskdrives]: }

So how can I get Puppet to treat each disk and network interface 
separately in the loop and generate multiple Nagios checks?

Thanks,
Jonathan
(Continue reading)

Erik Dalén | 10 Jul 2012 11:37
Picon
Gravatar

Re: [Puppet Users] Array mapping

On 10 July 2012 11:21, Jonathan Gazeley <jonathan.gazeley <at> bristol.ac.uk> wrote:
> Some of my facter variables are formatted as a comma-separated list of
> network interfaces, and of system disks. I wish to create separate Nagios
> checks for each. When I reference the variable like this, the individual
> entries from the list are not treated as an array, but as a concatenated
> string.
>
> notify{ [$diskdrives]: }
>
> So how can I get Puppet to treat each disk and network interface separately
> in the loop and generate multiple Nagios checks?

Use the split() function to split the string into an array:
http://docs.puppetlabs.com/references/stable/function.html#split

-- 
Erik Dalén

--

-- 
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 <at> googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe <at> googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.


Gmane