How to force reinstall package with Ansible?

I use Ansible to deploy .deb packages from my own repository.

Sometimes a developer may forget to change the package number, so there will be a new package in the repository with the old version. This is not necessary, so I would like to always reinstall the package. How can i do this?

For apt module force=yesoption force=yes. Ansible documentation says:

If yes, forcibly installs / removes.

But it is like taking any warnings by force. At least when I turn it off, Ansible is blocked with an untrusted source warning. (Both storage and servers are on the same intranet, so there should be no problems)

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 is blocked by warnings in the same way.

Is there a way to always reinstall the package and avoid being blocked by interactivity?

+4
source share
1 answer

The correct way is to use the correct version number. But if you do not want to apply this, the easiest way is to remove the package first and then install it again. This is almost the same as reinstallation.

- name: remove package
  apt: name=package_name state=absent

- name: install package
  apt: name=package_name state=present update_cache=yes
+4
source

Source: https://habr.com/ru/post/1619795/


All Articles