2

I use apt autoremove in my playbook:

- name: remove autoinstalled crap
  apt:
    autoremove: yes

I would like to see list of removed packages in the output of ansible-playbook. Is it possible?

1 Answer 1

4

There is no standard procedure. The list of the removed packages must be created. For example, register the returned data

    - name: remove autoinstalled crap
      apt:
        autoremove: yes
      register: result

select lines with removed packages and map regex_replace second groups which should be the names of the removed packages

    - set_fact:
        pkg_removed: "{{ result.stdout_lines|
                         select('regex', '^Removing (.*)$')|
                         map('regex_replace', '^(.*?) (.*?) (.*)$', '\\2')|
                         list }}"
    - debug:
        var: pkg_removed

give (after the recent update of Ubuntu 20.04)

  pkg_removed:
  - linux-headers-5.4.0-29-generic
  - linux-headers-5.4.0-29
  - linux-headers-5.4.0-31-generic
  - linux-headers-5.4.0-31
  - linux-modules-extra-5.4.0-29-generic
  - linux-image-5.4.0-29-generic
  - linux-modules-extra-5.4.0-31-generic
  - linux-image-5.4.0-31-generic
  - linux-modules-5.4.0-29-generic
  - linux-modules-5.4.0-31-generic
2
  • Thank you, it works. Only one thing: I've added when: result.changed to both tasks (otherwise it fails if no packages were deleted). BTW, it is noisily a bit. Unfortunately, it seems like there is no way to suppress set_fact output.
    – edo1
    Jun 20, 2020 at 23:03
  • Try other callback plugin. Jun 21, 2020 at 1:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .