Delete old databases

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

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 ?

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

my_dbs:
  db1:
    state: present
  db2:
    state: absent

And your task could look like this:

- name: add/remove databases
  whatever_db_module: name={{item.key}} state={{item.value.state}}
  with_dict: my_dbs