To manages apt packages for Debian/Ubuntu and friends use apt module of Ansible. The autoremove is used to remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed as dependencies changed or the package(s) needing them were removed in the meantime.
To do so you run the apt command or apt-get command as follows:
$ sudo apt autoremove
OR
$ sudo apt-get autoremove
For removing unused Linux kernel on a Debian/Ubuntu Linux use:
$ sudo apt -y --purge autoremove
## OR ##
$ sudo apt-get -y --purge autoremove
Running sudo apt-get autoremove with ansible
Update your yml file as follows:
- name: Clean unwanted olderstuff apt: autoremove: yes purge: yes
Where,
- autoremove : If yes, remove unused dependency packages for all module states except build-dep. It can also be used as the only option. You must use Ansible version 2.1.
- purge : This will force purging of configuration files if the module state is set to yes.
Here is my vpn.yml file:
--- - hosts: vpn become: true become_user: root tasks: - name: Updating host using apt apt: update_cache: yes upgrade: dist - name: Update kernel to spefic version apt: name: "{{ k_ver }}" state: latest - name: Clean unwanted olderstuff apt: autoremove: yes purge: yes
My hosts file:
[vpn:vars] ansible_user=vivek k_ver="linux-image-4.10.0-38-generic" [vpn] blr-vpn mum-vpn tx-vpn tok-vpn del-vpn lon-vpn
Run it as follows:
$ ansible-playbook -i hosts vpn.yml
OR
$ export ANSIBLE_HOSTS=~/opshelper/hosts
$ ansible-playbook vpn.yml
A note about running apt autoremove on LXD based vm
You can update your yml file as follows to run same command on three vm named db, proxy, and www as follows:
- name: Run lxc apt-autoremove on cbz01 lxd host per vm command: /usr/bin/lxc exec {{ item }} -- /usr/bin/apt-get --purge -y autoremove with_items: - db - proxy - www
🐧 Please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 1 comment... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Where I can find your full playbook?