Home » Php » Puppet : Specifying a version of a package to install

Puppet : Specifying a version of a package to install

Posted by: admin November 30, 2017 Leave a comment


Apparently this is not possible, but I can’t believe that I’m the only one who need it.

I want to specify the version of php to install because I’m working on an old project requiring php 5.2.

Actually my VM is based on Oneiric with php 5.3

Do you have any solution to do this ?


You can specify a version:

package { 'php' :
  ensure => '5.2' ,

However, if that version of PHP RPM/Deb/package isn’t available in your upstream repo, then you’ll want to either:

  1. Find an alternate repo that has that package, and add it to your repo list
  2. Set up your own repo with the package
  3. Install from your filesystem, by providing a path to the package:

    package { 'php' :
      ensure => '5.2' ,
      source => '/some/path/to/php-5.2.rpm' ,

This is pretty close to how I use custom apt repositories in puppet with their gpg keys

# put downloaded pgp keys into modulename/files/pgp/
# this will copy them all into /tmp
file { '/tmp/pgp-keys':
        ensure  => directory,
        recurse => true,
        source  => 'puppet:///modules/modulename/pgp',

# add any keys that you need
exec { 'apt-key add':
        command     => '/usr/bin/apt-key add /tmp/pgp-keys/number1.gpg.key &&/
                        /usr/bin/apt-key add /tmp/pgp-keys/number2.gpg.key',
        subscribe   => File['/tmp/pgp-keys'],
        refreshonly => true,

# make sure you add your custom apt repository
file { 'cassandra.sources.list':
        ensure  => 'present',
        path    => '/etc/apt/sources.list.d/cassandra.sources.list',
        source  => 'puppet:///modules/modulename/cassandra.sources.list',
        require => Exec['apt-key add'],

# update your package list
exec { 'apt-get update':
        command => '/usr/bin/apt-get update',
        require => File['cassandra.sources.list'],

# Install your specific package - I haven't actually used this yet, 
# based on answer by opsmason
package { 'cassandra':
        ensure  => '1.2.0',
        require => Exec['apt-get update'],