Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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:

php::pear {
  ['ldap', 'mysql', 'sqlite', 'tidy', 'xmlrpc']: 
    ensure => 'installed';
  ['ps','snmp']:
    ensure => 'absent';
}
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.