Ask Your Question
0

check if the package is installed and compare the version

asked 2016-06-17 03:03:42 -0500

stanislas93 gravatar image

Hi,

I'm not an expert on puppet and I have some syntax problems

I would check if the package is installed and compare the version of the package with the version I would like to see installed

IF the package is installed with the correct version DO NOTHING

BUT if it is not installed or installed but not the correct version, uninstall it and download the right package with the right version and install

I started to do something that is not terrible and I would like your help to answer my problem

thank you very much in advance

here is the beginning of what I've done

if package { 'xyz' ensure=> '1.2'}
    do nothing

    else {
    exec => rpm -e xyp-packagebadversion


file { "/tmp/xyz-packagegoodversion":
       ensure => 'present',
       source => "puppet:///modules/package/xyz-packagegoodversion"

}

package { "xyz":
        ensure => '1.2',
        provider => 'rpm',
        source => "/tmp/xyz-packagegoodversion"
        }
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2016-06-17 21:09:12 -0500

DarylW gravatar image

updated 2016-06-20 14:41:30 -0500

I believe that you can use the 'ensure' parameter to specify package version on the package resource.. You'll have to use the exact version string, which can be seen on a system where you the correct version installed by running puppet resource package packagename

ubuntu:~/puppet-jira$ puppet resource package | head -n 9
package { 'CFPropertyList':
  ensure => ['2.2.8'],
}
package { 'accountsservice':
  ensure => '0.6.40-2ubuntu5',
}
package { 'acl':
  ensure => '2.2.52-2',
}

And here's the relevant section from puppet describe package

- **ensure**
    What state the package should be in. On packaging systems that can
    retrieve new packages on their own, you can choose which package to
    retrieve by specifying a version number or `latest` as the ensure
    value. On packaging systems that manage configuration files separately
    from "normal" system files, you can uninstall config files by
    specifying `purged` as the ensure value. This defaults to `installed`.
    Valid values are `present` (also called `installed`), `absent`,
    `purged`, `held`, `latest`. Values can match `/./`.

------------- EDIT -----------------

I just tried it out locally, and it seems to behave as I expected

ubuntu:~/puppet-jira$ apt-cache madison mysql-client
mysql-client | 5.6.30-0ubuntu0.15.10.1 | http://us.archive.ubuntu.com/ubuntu/ wily-updates/main amd64 Packages
mysql-client | 5.6.30-0ubuntu0.15.10.1 | http://security.ubuntu.com/ubuntu/ wily-security/main amd64 Packages
mysql-client | 5.6.25-0ubuntu1 | http://us.archive.ubuntu.com/ubuntu/ wily/main amd64 Packages
 mysql-5.6 | 5.6.25-0ubuntu1 | http://us.archive.ubuntu.com/ubuntu/ wily/main Sources
 mysql-5.6 | 5.6.30-0ubuntu0.15.10.1 | http://us.archive.ubuntu.com/ubuntu/ wily-updates/main Sources
 mysql-5.6 | 5.6.30-0ubuntu0.15.10.1 | http://security.ubuntu.com/ubuntu/ wily-security/main Sources
ubuntu:~/puppet-jira$ sudo puppet apply -e "package{ 'mysql-client': ensure => '5.6.30-0ubuntu0.15.10.1',}"
Notice: Compiled catalog for ubuntu in environment production in 0.05 seconds
Notice: /Stage[main]/Main/Package[mysql-client]/ensure: created
Notice: Applied catalog in 27.76 seconds
ubuntu:~/puppet-jira$ puppet resource package mysql-client
package { 'mysql-client':
  ensure => '5.6.30-0ubuntu0.15.10.1',
}
ubuntu:~/puppet-jira$ sudo puppet apply -e "package{ 'mysql-client': ensure => '5.6.25-0ubuntu1',}"
Notice: Compiled catalog for ubuntu in environment production in 0.05 seconds
Notice: /Stage[main]/Main/Package[mysql-client]/ensure: ensure changed '5.6.30-0ubuntu0.15.10.1' to '5.6.25-0ubuntu1'
Notice: Applied catalog in 1.67 seconds
ubuntu:~/puppet-jira$ puppet resource package mysql-client
package { 'mysql-client':
  ensure => '5.6.25-0ubuntu1',
}
edit flag offensive delete link more

Comments

I don't think the package will be uninstalled and reinstalled if it's at the wrong version though, per the poster's requirement?

Alex Harvey gravatar imageAlex Harvey ( 2016-06-18 13:08:03 -0500 )edit

Behind the scenes it uses this command to 'downgrade' a package on Ubuntu ---- Debug: Executing: '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold --force-yes install mysql-client=5.6.25-0ubuntu1'

DarylW gravatar imageDarylW ( 2016-06-18 23:45:41 -0500 )edit
0

answered 2016-06-17 11:19:51 -0500

stanislas93 gravatar image

thank you

I understand, I do not use puppet as he would really

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-06-17 03:03:42 -0500

Seen: 1,322 times

Last updated: Jun 20 '16