Ansible Yum Update revision from given version

Im working on a project with several versions each version has it’s own revision in the repo

Example:
fooproject-2.2.1-r4000.rpm
fooproject-2.2.1-r4005.rpm

fooproject-3.0.1-r4015.rpm

There’s a server on version 2 rev 4000

doing the command-> yum install fooproject2.2.1
it will install → fooproject-2.2.1-r4005.rpm

now on ansible I created a task that does:

  • name: Update fooproject revision
    yum:
    name: fooproject*{{ foo_version }}*
    state: present

this will say that the server (in rev4000) is on the latest version

already tried

  • name: Update fooproject revision
    yum:
    name: fooproject*{{ foo_version }}*
    state: latest

and it will install version 3

Workaround at the moment:

Im using
command: yum install

Is there a way to use the yum module for this case?

Hi Tiago,

Although you have provided sufficient information, it was not a simple matter to try to reproduce the issue. :slight_smile:

Here are some instructions for anyone wanting to try to reproduce this:

I chose to use webmin as the package to test with since I had easy access to it.

`

[Webmin]
name=Webmin Distribution Neutral
#baseurl=http://download.webmin.com/download/yum
mirrorlist=http://download.webmin.com/download/yum/mirrorlist
enabled=1

`

  • Fetch and install the GPG key:

`

wget http://www.webmin.com/jcameron-key.asc
rpm --import jcameron-key.asc

`

`

yum install webmin-1.490-1

`

Now, you should be in a position to test the Ansible tasks Tiago provided as examples. i.e.

`

  • name: Update webmin revision
    yum:
    name: “webmin1.49
    state: present

`

and

`

  • name: Update Webmin revision
    yum:
    name: “webmin1.49
    state: latest

`

I looked at the code for the Ansible yum module and I believe that the correct state that you should be using for your purposes is: “latest”.

I believe the reason the issue occurs is that on line 905, the is_installed function returns true because it works out that the package is indeed installed and it then adds the specified package spec (webmin1.49) to the list of packages that need “updating” instead of the list of packages which need “installing”.

So this means that the Ansible yum module will be carrying out an action equivalent to:

`
yum update ‘webmin1.49

`

instead of:

`
yum install ‘webmin1.49

`

If you run those two commands manually on the command line, this the output you would see:

`

yum update ‘webmin1.49

Loaded plugins: changelog, fastestmirror, keys, merge-conf, ps, remove-with-leaves, show-leaves, verify
Loading mirror speeds from cached hostfile

Dependencies Resolved