I can understand according to http://docs.puppetlabs.com/guides/language_guide.html that I can pass an array to a definition.
define php::pear() {
package { "`php-${name}": ensure => installed }
}
php::pear { ['ldap', 'mysql', 'ps', 'snmp', 'sqlite', 'tidy', 'xmlrpc']: }
However, is there a way that I can pass more than one array to do the same thing? For instance, if I wanted some pear libraries installed, and some absent, could I do this?
define php::pear($ensure) {
package { "`php-${name}": ensure => $ensure }
}
php::pear { ['ldap', 'mysql', 'ps', 'snmp', 'sqlite', 'tidy', 'xmlrpc']:
ensure => ['installed', 'installed', 'absent', 'absent', 'installed', 'installed', 'installed']
}
Firstly, is something like this possible, or are there better ways of doing something like this with multidimensional arrays or something?
Any help would be appreciated, I'm finding the puppet documentation lacking a little in this area.
Cheers
I don't think you can really do what you're talking about. You'd just end up passing the same large array to both things, and in your example it looks like you want to iterate over two arrays at once.
And even more importantly, even if you could, that's really ugly and hard to read. It takes some careful reading to figure out which things are supposed to be absent or present.
The following syntax will work with puppet, is much easier to read without confusion, much easier to make changes to later, and is probably actually fewer characters anyways:
Yeah, you could accomplish that by nesting arrays (
[ ['ldap', 'installed'], ['mysql', 'installed'],...
) and tweaking the functions.But, really, that's only going to serve to make your config messy and hard to read. Just define a class that puts the packages how you want them, and include the class.