Using yum module to install latest or defined version of a package

9,836 views
Skip to first unread message

Byron Schlemmer

unread,
Aug 21, 2013, 7:27:09 AM8/21/13
to ansible...@googlegroups.com
Hi all,

I'm trying to work out the best way to either install the latest version or a specified version of a package dependent on a group_vars variable passed.

That is, my group_vars/group contains:

mypackage: 1.0

But it could be changed to

mypackage: latest

And I want package installation to occur accordingly.

My play has:

- name: install mypackage rpm
  yum:  name=mypackage state=latest
  when: mypackage_version == "latest"

- name: install mypackage rpm
  yum:  name=mypackage-{{ mypackage_version }} state=installed
  when: mypackage_version != "latest"

Now this works but I end up with output from both packages:

TASK: [install mypackage rpm]
****************************************
ok: [myhost00]

TASK: [install mypackage rpm]
****************************************
skipping: [myhost00]

Is there a way to silence the output on the task that did not run? Is this the best way to accomplish this or should I abstract with an include in some fashion?

Thanks,


James Cammarata

unread,
Aug 21, 2013, 8:35:51 AM8/21/13
to ansible...@googlegroups.com
Use state=latest and it will install the latest version. To install a specific version, use name=package-X.Y

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--

James Cammarata <jcamm...@ansibleworks.com>
Sr. Software Engineer, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Patrick Regan

unread,
Aug 21, 2013, 8:41:20 AM8/21/13
to ansible...@googlegroups.com
On Wed, Aug 21, 2013 at 8:35 AM, James Cammarata <jcamm...@ansibleworks.com> wrote:
Use state=latest and it will install the latest version. To install a specific version, use name=package-X.Y

I think he understands this. If you take a closer look at his play he is using latest if the variable contains latest, and is using `name` when it does not. He's asking if there's a way to keep Ansible from showing the skipped task in the output.



--

--
Patrick Regan

Byron Schlemmer

unread,
Aug 21, 2013, 9:58:00 AM8/21/13
to ansible...@googlegroups.com

Indeed. Or to just run either or dependent on the conditional. I'm basically trying to find out if there is a good way to replicate puppets package resource, eg:

package { mypackge:
  ensure => $mypackage_version;
}

Where is $mypackage_version = latest it installs the latest package or 1.0 it installs version 1.0.

James Cammarata

unread,
Aug 21, 2013, 12:39:29 PM8/21/13
to ansible...@googlegroups.com
Sorry about that, that's what I get for answering questions before my second cup of coffee. I was completely focused on the when: line.

Currently, there is no way to suppress skipped messages.

Byron Schlemmer

unread,
Aug 21, 2013, 12:54:42 PM8/21/13
to ansible...@googlegroups.com
Understood.

Thanks James.

Michael DeHaan

unread,
Aug 21, 2013, 10:29:02 PM8/21/13
to ansible...@googlegroups.com
"
package { mypackge:
  ensure => $mypackage_version;
}
"

What James said, yes.

you do "name=xyz=1.2.3.4 state=installed"

It also supports other operations like ">" and so on.

It should report unchanged here, not skipped.   Let me know if you see it reporting skipped.

Conditionals like "when:" do report skipped when things are skipped, yes.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Gaston Acosta

unread,
Oct 24, 2014, 9:19:05 AM10/24/14
to ansible...@googlegroups.com
Hi all, 

I resolve this using something like this:

yum: pkg=httpd-{{ httpd_version | default('*') }} state=latest
as the documentation says :
"Package name, or package specifier with version, like name-1.0. When using state=latest, this can be '*' which means run: yum -y update. You can also pass a url or a local path to a rpm file."

Hope that helps

Dick Davies

unread,
Oct 28, 2014, 8:24:26 AM10/28/14
to ansible list
I just do it with:

group_vars/relevantgroup:

httpd_rpm: httpd # if you aren't fussy - this will get you the latest
at the time of the first run
# or : httpd_rpm: http-2.0.36 # if you want a specific version

task looks like :

- name: install {{ httpd_rpm }}
yum: name={{ httpd_rpm }} state=present

In my experience, state=latest is probably a Bad Idea in the config
management world
- packages changing underneath you either
a) should reload the service (potentially causing an outage) or
b) don't reload the service (almost definitely storing up trouble at
next reboot)

in both cases there's also the risk that a config file default will
change and ruin your day.
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/c8ebc35e-6158-4810-8483-cfd90a125082%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages