Ansible Yum Update revision from given version

404 views
Skip to first unread message

Tiago Silva

unread,
Jan 28, 2017, 1:11:12 AM1/28/17
to Ansible Project
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 fooproject*2.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?

Jinesh Choksi

unread,
Feb 1, 2017, 8:52:14 AM2/1/17
to Ansible Project
Hi Tiago,

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

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.


- Setup a /etc/yum.repos.d/webmin.repo file with the following contents (source: http://www.webmin.com/rpm.html):

[Webmin]
name=Webmin Distribution Neutral
enabled=1


- Fetch and install the GPG key:

rpm --import jcameron-key.asc


- You can view the list of available versions of Webmin here: http://download.webmin.com/download/yum/


- For the reproduction, install, say version: webmin-1.490-1.noarch

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: "webmin*1.49*"
   state: present

and

- name: Update Webmin revision
 yum:
    name: "webmin*1.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 (webmin*1.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 'webmin*1.49*'

instead of:

yum install 'webmin*1.49*'

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

#  yum update 'webmin*1.49*'
Loaded plugins: changelog, fastestmirror, keys, merge-conf, ps, remove-with-leaves, show-leaves, verify
Loading mirror speeds from cached hostfile
 * epel: mirror.slu.cz
Resolving Dependencies
--> Running transaction check
---> Package webmin.noarch 0:1.490-1 will be updated
---> Package webmin.noarch 0:1.831-1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                   Arch                      Version                     Repository                 Size
=================================================================================================================
Updating:
 webmin                    noarch                    1.831-1                     Webmin                     27 M

Transaction Summary
=================================================================================================================
Upgrade  1 Package

Total size: 27 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2017-02-01.13-26.9KDStM.yumtx


#  yum install 'webmin*1.49*'
Loaded plugins: changelog, fastestmirror, keys, merge-conf, ps, remove-with-leaves, show-leaves, verify
devops-artifacts                                                                          | 1.5 kB  00:00:00
Loading mirror speeds from cached hostfile
 * epel: mirror.slu.cz
Resolving Dependencies
--> Running transaction check
---> Package webmin.noarch 0:1.490-1 will be updated
---> Package webmin.noarch 0:1.499-1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                   Arch                      Version                     Repository                 Size
=================================================================================================================
Updating:
 webmin                    noarch                    1.499-1                     Webmin                     15 M

Transaction Summary
=================================================================================================================
Upgrade  1 Package

Total download size: 15 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2017-02-01.13-26.u8mk1v.yumtx


The above hence explains why you are getting the behaviour you see.

Ansible's yum module is doing a "yum update" instead of a "yum install".

I don't know if the Ansible developers will see the above as a bug and the only workaround I can see is that you should setup an Ansible task to uninstall the package spec and then install it (with state=latest) which will force the Ansible yum module it to do a "yum install" and give you the behaviour you want.

Regards,
Jinesh
Reply all
Reply to author
Forward
0 new messages