Sunday 3 April 2016

Require Mutiple Dependencies With Puppet

The puppet cookbook gives a few different options for installing multiple packages at once.
e.g.
    # 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' }

However, I had over 30 packages to install and needed some of these packages for a subsequent command.

  • If I used an array, the title is the array and you can't use it in require.
  • When I moved the array to name I got the error Name must be a String not Array.
  • If I don't use an array, I will have to chain the 30 package calls with individual requires.

The solution isn't documented on that cookbook page, but instead of using require on the dependent task you can use notify on the package task.
e.g.
    

$packages = [
                'bison',
                'build-essential',
                'ccache',
                'curl',
                'flex',
                'g++-multilib',
                'gcc-multilib',
                'git',
                'gnupg',
                'gperf',
                'lib32ncurses5-dev',
                'lib32readline-gplv2-dev',
                'lib32z1-dev',
                'lib32z-dev',
                'libc6-dev-i386',
                'libesd0-dev',
                'libgl1-mesa-dev',
                'liblz4-tool',
                'libncurses5-dev',
                'libsdl1.2-dev',
                'libwxgtk2.8-dev',
                'libx11-dev',
                'libxml2',
                'libxml2-utils',
                'lzop',
                'maven',
                'pngcrush',
                'schedtool',
                'squashfs-tools',
                'unzip',
                'x11proto-core-dev',
                'xsltproc',
                'zip',
                'zlib1g-dev'
              ]
  package { $packages:
    ensure => 'installed',
    notify => Exec['install repo']   
  }

  exec { 'install repo':
    cwd     => '/usr/local/bin',
    command => 'curl https://storage.googleapis.com/git-repo-downloads/repo >repo',
    creates => '/usr/local/bin/repo',
  }