Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove package ansible playbook

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 ?

like image 642
Hpatoio Avatar asked Apr 28 '15 08:04

Hpatoio


People also ask

How do I uninstall a yum package?

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.

What is package module in Ansible?

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.


Video Answer


1 Answers

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
like image 179
udondan Avatar answered Oct 11 '22 06:10

udondan