check if the package is installed and compare the version

547 views
Skip to first unread message

puppetstan

unread,
Jun 17, 2016, 5:23:45 AM6/17/16
to Puppet Users

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"
        }

Gareth Rushgrove

unread,
Jun 17, 2016, 5:52:42 AM6/17/16
to puppet...@googlegroups.com
HI Stanislas

On 17 June 2016 at 10:23, puppetstan <stanisla...@gmail.com> wrote:
> 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
>

Puppet as a language is declarative, rather than imperative. So the
package resource actually does exactly what you describe here.

package { "xyz":
ensure => '1.2',
}

The above would, if it finds xyz installed at version 1.2 do nothing.
If it's not installed, or installed at a previous version, it will
update the package to the specified version.

Gareth

>
> 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"
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/4835a155-1a2c-4857-b0a4-090dd1a28657%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gareth Rushgrove
@garethr

devopsweekly.com
morethanseven.net
garethrushgrove.com

puppetstan

unread,
Jun 17, 2016, 9:27:58 AM6/17/16
to Puppet Users
Ithank you

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

Reply all
Reply to author
Forward
0 new messages