Ansible - How to backup all MySQL databases?
ansible, mysql
Solution
A patch to adds `name=all` that allows a user to dump or import all data was merged into devel recently, it's not available yet in 1.9.1, but it's already shown in this part of the documentation.
# Dumps all databases to hostname.sql
- mysql_db: state=dump name=all target=/tmp/{{ inventory_hostname }}.sql
Hopefully this will soon be available in a stable release. (Run `sudo pip install ansible --upgrade` to upgrade.)
Problem
I need to take a backup of all existing MySQL databases on my server with Ansible. I'm aware of mysql_db module. It takes the names of the databases I'd like to manipulate on one by one, so I must get the list of existing databases before using that module. Is there any way to backup all MySQL databases at once or to get a list of existing databases with Ansible?