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'm working through the puppet documentation. One of the exercises is to use some conditional logic to write a general install manifest:

Exercise: Use the $operatingsystem fact to write a manifest that installs a build environment on Debian-based (“debian,” “ubuntu”) and Enterprise Linux-based (“centos,” “redhat”) machines. (Both types of system require the gcc package, but Debian-type systems also require build-essential.)

I wrote code that works, but because my machine is a centos machine, I have no way of checking if the branch works:

$build_packages = $::operatingsystem ? {
  /(?i)centos|redhat/ => 'gcc',
  /(?i)debian|ubuntu/ => ['gcc','build-essential'],
  default => undef
}

notify {"build_packages":
  message => "Build packages for ${::operatingsystem} are: ${build_packages}\n",
  before => Package['build']
}

package {'build':
  ensure => installed,
  name => $build_packages
}

My question is, if I was on a debian or ubuntu system, would this work? Specifically, if I set $build_packages to an array, will the package resource do the right thing and install the two packages? Or should I redefine that resource like this?:

package {$build_packages:
    ensure => installed
}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

The second one, package {$build_packages:. That gets expanded into a resource for each member of the array, and each package in the array will be installed.

Note that the array will, however, break the notify resource since its message is assuming that $build_packages is a string.

share|improve this answer
    
Actually, the string interpolation, WILL work. It will just mash the array contents together. So you get 'gccbuild-essential' as the value there. Thanks for the answer! –  Avery Chan May 31 '13 at 7:53

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.