Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can understand according to 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.


share|improve this question

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';
    ensure => 'absent';
share|improve this answer

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

Your Answer


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.