# Delete old databases

**URL:** <https://forum.ansible.com/t/delete-old-databases/15067>\
**Category:** Ansible Project\
**Created:** [April 22, 2014, 4:28pm UTC](https://forum.ansible.com/t/delete-old-databases/15067 "2014-04-22T16:28:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yoann\_DAVID](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@Yoann\_DAVID](https://forum.ansible.com/u/Yoann_DAVID)\
**Post date:** [April 22, 2014, 4:28pm UTC](https://forum.ansible.com/t/delete-old-databases/15067/1 "2014-04-22T16:28:37Z")

</div>

I want to create a playbook to create but also delete databases that are not anymore in my configuration file.

Lets take an example, I have a variable listing database to create :

db:

- foo
- bar

First run DB foo and bar are created, if I remove bar from my list, when I run ansible bar is always in my server.

I would find a solution to address the deletion of a previously added db but not available anymore.

Somewhere something like this playbook (for users) : [https://github.com/jurgenhaas/ansible-user-management](https://github.com/jurgenhaas/ansible-user-management)

Any idea to deal with this problem ?  
How do you deal with resources added then removed to delete them on server ?

Create a temporary playbook to explicitly remove the resources ?

---

<div class="post-metadata">

**Author:** ![James\_Cammarata](https://avatars.discourse-cdn.com/v4/letter/j/7c8e57/32.png) [@James\_Cammarata](https://forum.ansible.com/u/James_Cammarata)\
**Post date:** [April 22, 2014, 6:37pm UTC](https://forum.ansible.com/t/delete-old-databases/15067/2 "2014-04-22T18:37:54Z")

</div>

You might want to look at  
[http://docs.ansible.com/playbooks\_loops.html#looping-over-hashes](http://docs.ansible.com/playbooks_loops.html#looping-over-hashes), where you  
could create a dictionary structure like:

my\_dbs:  
&nbsp;&nbsp;db1:  
&nbsp;&nbsp;&nbsp;&nbsp;state: present  
&nbsp;&nbsp;db2:  
&nbsp;&nbsp;&nbsp;&nbsp;state: absent

And your task could look like this:

- name: add/remove databases  
&nbsp;&nbsp;whatever\_db\_module: name={{item.key}} state={{item.value.state}}  
&nbsp;&nbsp;with\_dict: my\_dbs
