A collection of task oriented solutions in Puppet

 

Install multiple packages

Challenge

You want to install multiple packages

Solution

class packages {

  # the first, most obvious solution is
  package { 'screen': ensure => 'installed' }
  package { 'strace': ensure => 'installed' }
  package { 'sudo':   ensure => 'installed' }


  # you can use a global package parameter
  Package { ensure => 'installed' }

  package { 'screen': }
  package { 'strace': }
  package { 'sudo':   }

  # you can specify the packages in an array ...
  $enhancers = [ 'screen', 'strace', 'sudo' ]
  package { $enhancers: ensure => 'installed' }


  # ... and even combine it a global package parameter
  Package { ensure => 'installed' }

  $enhancers = [ 'screen', 'strace', 'sudo' ]

  package { $enhancers: }

}

Explanation

There are often times you'll need to install more than a single package in one of your modules or manifests. While you can install multiple packages with multiple package resources, one resource per package to install, there are a couple of extra formatting options to reduce duplication slightly.

As a reminder the package type only requires you to specify the package name and the desired status of the package. The 'ensure' attribute will accept either 'present' or 'installed'.

It's worth mentioning that no matter which of the above formats you specify the packages will still be installed one by one. None of those snippets will install multiple packages simultaneously in a way that will satisfy a circular dependency. So if A requires B and B requires A there is no way in pure puppet to install them. And you should probably rethink your packages.

This will use whichever installation provider Puppet considers to be the default for this platform and install the latest version of the packages that it finds in the hosts configured software repos when the manifest first runs. Once the packages are installed Puppet will not track new versions of the packages.

See also