I'm using Ansible to deploy .deb packages from a custom repository.
Sometimes a developer can forget to change the package number, so the repository will have the new package with the old version. This is unnecessary, so I would like to always reinstall the package. How do I do that?
There is the force=yes
option for apt module
. Ansible documentation says:
If
yes
, force installs/removes.
But that seems to be about force-accepting any warnings. At least when I turn it off, Ansible gets blocked with a warning about an untrusted source. (Both the repository and the servers are in the same intranet, so that should not be an issue)
I could use this:
- name: force-reinstall myservice
shell: apt-get --reinstall install myservice
But this way I cannot use other options for apt module
, and Ansible gets blocked on warnings the same way.
Is there a way to always reinstall a package and avoid blocking on any interactivity?
The proper way is definitely to use the correct version number. But if you don't want to enforce that then the easiest workaround is to first remove the package and then install it again. That is effectively same as reinstalling.
- name: remove package
apt: name=package_name state=absent
- name: install package
apt: name=package_name state=present update_cache=yes