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]
Use state=latest and it will install the latest version. To install a specific version, use name=package-X.Y
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.
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.
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.
"
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.
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
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.