# Remove packages

**URL:** <https://forum.ansible.com/t/remove-packages/15866>\
**Category:** Ansible Project\
**Created:** [August 6, 2014, 8:17am UTC](https://forum.ansible.com/t/remove-packages/15866 "2014-08-06T08:17:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogene\_Laerce](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Diogene\_Laerce](https://forum.ansible.com/u/Diogene_Laerce)\
**Post date:** [August 6, 2014, 8:17am UTC](https://forum.ansible.com/t/remove-packages/15866/1 "2014-08-06T08:17:54Z")

</div>

Hi,

Is there a way, other that with a bash script, to do this  
command please (in Ansible of course.. 🙂 )?

$ apt-get remove package\*

Thank you,

---

<div class="post-metadata">

**Author:** ![Christian\_Rusa](https://avatars.discourse-cdn.com/v4/letter/c/f0a364/32.png) [@Christian\_Rusa](https://forum.ansible.com/u/Christian_Rusa)\
**Post date:** [August 6, 2014, 8:31am UTC](https://forum.ansible.com/t/remove-packages/15866/2 "2014-08-06T08:31:48Z")

</div>

It is really easy just use apt module with state=absent

[http://docs.ansible.com/apt\_module.html](http://docs.ansible.com/apt_module.html)

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [August 6, 2014, 8:39am UTC](https://forum.ansible.com/t/remove-packages/15866/3 "2014-08-06T08:39:07Z")

</div>

> $ apt-get remove package\*

From [http://docs.ansible.com/apt\_module.html](http://docs.ansible.com/apt_module.html):

> `
> 
> # Remove “foo” package
> 
> - apt: name=foo state=absent
> 
> `

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Diogene\_Laerce](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Diogene\_Laerce](https://forum.ansible.com/u/Diogene_Laerce)\
**Post date:** [August 6, 2014, 8:48am UTC](https://forum.ansible.com/t/remove-packages/15866/4 "2014-08-06T08:48:59Z")

</div>

Thanks but I did see that.

Still it doesn't seem to remove all related packages as the "\*"  
implies.

For example, I tried to remove apache and all related packages,  
and apache2-doc is still installed, as some others.

So 2 solutions : list all packages and remove them one by one, or  
the "\*" feature in a bash script.

Cheers,

---

<div class="post-metadata">

**Author:** ![Paul\_Totterman](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@Paul\_Totterman](https://forum.ansible.com/u/Paul_Totterman)\
**Post date:** [August 6, 2014, 8:51am UTC](https://forum.ansible.com/t/remove-packages/15866/5 "2014-08-06T08:51:11Z")

</div>

> $ apt-get remove package\*

Reading a bit more carefully, if your problem is with the glob, maybe try a playbook like this:

`

---

<div class="post-metadata">

**Author:** ![Diogene\_Laerce](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Diogene\_Laerce](https://forum.ansible.com/u/Diogene_Laerce)\
**Post date:** [August 6, 2014, 9:01am UTC](https://forum.ansible.com/t/remove-packages/15866/6 "2014-08-06T09:01:16Z")

</div>

Thank you, it does the trick. 🙂

---

<div class="post-metadata">

**Author:** ![vaida.dan](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@vaida.dan](https://forum.ansible.com/u/vaida.dan)\
**Post date:** [August 7, 2014, 1:17pm UTC](https://forum.ansible.com/t/remove-packages/15866/7 "2014-08-07T13:17:57Z")

</div>

Hello,

This works just fine for me:

`

- name: uninstall apache-related packages  
apt: \>  
pkg={{ item }}  
state=absent  
purge=yes  
force=yes  
with\_items:
- apache2\*  
sudo: yes

`
