So you want something like:
if software is not installed
install new software
else installed version is older than new version
remove old software
install new software
(perhaps reconfigure and restart services)
fi
As Tim suggests, this is better handled by distribution packaging, but
if you have some custom setup, this may not be possible.
On the surface it looks like something that could be achieved with one
tasks to determine the current state and register the result, follow
by 2 tasks to conditionally add/remove the software.
The tricky bit is determining which package is newer. If your version
numbers are simple integers you may be able to get away with something
like
- name: determine newest installed software version
shell: find /opt/ -n 'foo-v*' | sed 's/\/opt\/foo-v//' | sort -rn | head -1
register: installed
- name: remove old software versions
when: installed.stdout != '' and installed.stdout|int < new_version
command: to remove old software
- name: install new software version
when: installed.stdout == '' or installed.stdout|int < new_version
command: to install new software
where 'new_version' is a variable you have set somewhere.
The above code is untested but might form the basis for something that
works for you.
K
Kahlil (Kal) Hodgson GPG: C9A02289
Head of Technology (m) +61 (0) 4 2573 0382
DealMax Pty Ltd (w) +61 (0) 3 9008 5281
Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia
"All parts should go together without forcing. You must remember that
the parts you are reassembling were disassembled by you. Therefore,
if you can't get them together again, there must be a reason. By all
means, do not use a hammer." -- IBM maintenance manual, 1925