I've an EC2 instance create using Vagrant and provisioned with Ansible.
I've this task that install 2 package using apt
.
---
- name: Install GIT & TIG
action: apt pkg={{ item }} state=installed
with_items:
- git
- tig
I want now delete/remove tig
from my instance. I've removed it from my playbook and I've run vagrant provision
but the package is still there.
How can I do this ?
To remove the installed package we execute the "yum remove xxxx" command where xxxx=name of package. Confirmation of removal (Y). Confirm "Complete" message after the package is successfully removed. We can validate the removal of the package.
It is convenient to use in an heterogeneous environment of machines without having to create a specific task for each package manager. package calls behind the module for the package manager used by the operating system discovered by the module ansible. builtin. setup. If setup was not yet run, package will run it.
Ansible cannot automatically remove packages when you remove them from you playbook. Ansible is stateless. This means it will not keep track of what it does and therefore does not know what it did in recent runs or if your playbook/role has been modified. Ansible will only do what you explicitly describe in the playbook/role. So you have to write a task to remove it.
You can easily do this with the apt module.
- name: Remove TIG
apt:
pkg: tig
state: absent
become: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With