31

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 ?

JulienD
  • 3,172
  • 3
  • 16
  • 16

2 Answers2

51

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' ,
    }
    
kaiser
  • 21,817
  • 17
  • 90
  • 110
opsmason
  • 845
  • 6
  • 7
  • I tried the solution to change my preference/source list but I'm encountering problems with downloading the public key of archive.debian :s – JulienD Jul 24 '12 at 09:40
  • @opsmason: Does the version value need to be string? can you specify it as `ensure => 5.2`? – greenpool Feb 08 '15 at 02:31
  • @greenpool: the version is a string. Take httpd-2.4.29 as an example:: 2.4.29 isn't a float, it's a string! – opsmason Dec 13 '17 at 14:52
7

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'],
}
StuartW
  • 91
  • 1
  • 2