# Best way to clean hosts after changing roles?

**URL:** <https://forum.ansible.com/t/best-way-to-clean-hosts-after-changing-roles/16283>\
**Category:** Ansible Project\
**Created:** [September 18, 2014, 11:43pm UTC](https://forum.ansible.com/t/best-way-to-clean-hosts-after-changing-roles/16283 "2014-09-18T23:43:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Burton](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Kevin\_Burton](https://forum.ansible.com/u/Kevin_Burton)\
**Post date:** [September 18, 2014, 11:43pm UTC](https://forum.ansible.com/t/best-way-to-clean-hosts-after-changing-roles/16283/1 "2014-09-18T23:43:14Z")

</div>

Let’s say I have a role called ‘foo’ and that runs a playbook which installs a debian package ‘foo’.

If I remove host0 from the foo role, I need it to remove the debian package foo and stop the foo daemon.

How is that best done?

Leaving the daemon running and the package installed could lead to errors…

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [September 19, 2014, 1:59pm UTC](https://forum.ansible.com/t/best-way-to-clean-hosts-after-changing-roles/16283/2 "2014-09-19T13:59:40Z")

</div>

Removing a role or changing a machine's role is pretty rare. Most  
people in that situation would just shutdown that vm and spin up  
another with the new role. If you aren't running virtual machines then  
I'd suggestion having a separate playbook called something like  
"remove-role-X.yml" where X is the name of the role to remove. Then  
that playbook would know how to remove and shutdown anything from the  
X role. You'd have to work to make sure they are in sync, but again,  
changing a machine's role isn't something that's usually done that  
often.

---

<div class="post-metadata">

**Author:** ![Kevin\_Burton](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Kevin\_Burton](https://forum.ansible.com/u/Kevin_Burton)\
**Post date:** [September 19, 2014, 3:58pm UTC](https://forum.ansible.com/t/best-way-to-clean-hosts-after-changing-roles/16283/3 "2014-09-19T15:58:29Z")

</div>

Ah… gotcha… I guess that makes sense. We tend to use physical machines but we could just re-image or use docker.

I could have a remove-role that just resets the machine and removes packages.
