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?
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
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.