On Fri, 2 Nov 2018 at 17:15, Mauricio Tavares <[email protected]> wrote:

> (https://docs.ansible.com/ansible/latest/modules/package_module.html)
> can't be forced. Yeah, I am trying to abstract as much as possible. I
> guess I will try to uninstall and then reinstall package manually

Example playbook below will do that.
Initially it used the 'stat' module for each file, but since it's very
common for packages to have hundreds of files that became too slow.
So as a workaround I replaced it with a single command task that calls
stat on all files at once.
The Debian/RedHat test is very basic.
Pass the package name as command line option ( -e package=httpd).


- name: Ensure package is correctly installed
  become: true
  hosts: all
  tasks:

    - name: Ensure package is installed
      package:
        name: "{{ package }}"

    - name: Find package's files
      command: "{{ (ansible_os_family == 'Debian') | ternary( 'dpkg
--listfiles', 'repoquery --list') }} {{ package }}"
      register: pkg_files
      changed_when: false

    - name: Stat all files
      command: "stat {{ pkg_files.stdout_lines | join(' ') }}"
      changed_when: false
      failed_when: false
      register: stat_all_files

    - name: Force reinstall
      command: "{{ (ansible_os_family == 'Debian') | ternary( 'apt-get
install --', 'yum -y ') }}reinstall {{ package }}"
      args:
        warn: false
      when: stat_all_files.rc != 0




Dick

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAL8fbwOH8a-u%3D4_6%3DQScfad7ZhBXuSqELqsFMF3nCPUzU1dPNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to