FreeKB - Ansible mysql_db module
Ansible - mysql_db module

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

The mysql_db module is used to do various things against a mySQL or MariaDB database, such as creating a database, dropping a database, dumping a database, and so on. In this example, all databases will be dumped to a file named all.sql.

- name: dump all databases to /tmp/all.sql
   mysql_db:
     state: dump
     name: all
     target: /tmp/all.sql
     login_unix_socket: /var/lib/mysql/mysql.sock
...

 

If the following is returned, use the yum module to install epel-release and python-pip, and then use the pip module to install pymysql.

fatal: [server1.example.com]: FAILED! => {"changed": false, "msg": "The PyMySQL (Python 2.7 and Python 3.X) or MySQL-python (Python 2.X) module is required."}

 

The following can be done to import a .sql dump.

- name: restore all databases using /tmp/all.sql
   mysql_db:
     state: import
     name: all
     target: /tmp/all.sql
     login_unix_socket: /var/lib/mysql/mysql.sock
...

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 2a0ac in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |