MySQL with Ansible is an open-source automation tool that automates provisioning, configuration management, application deployment, orchestration, and many other manual IT processes. Unlike more simplistic management tools, Ansible users (like system administrators, developers, and architects) can use Ansible automation to install software, automate daily tasks, provision infrastructure, improve security and compliance, patch systems, and share automation across the entire organization.
How MySQL with Ansible works
Ansible works by connecting to what you want automated and pushing programs that execute instructions that tasks would have done manually. These programs utilize Ansible modules that are written based on the specific expectations of the endpoint’s connectivity, interface, and commands. Ansible then executes these modules (over standard SSH by default) and removes them when finished (if applicable).
There are no additional servers, daemons, or databases required. Typically you’ll work with your favorite terminal program, a text editor, and a version control system to keep track of changes to your content.
Remote server requirement
- MySQLdb (Python 2. x)
- PyMySQL (Python 2.7 and Python 3. X), or
- MySQL (command-line binary)
- mysqldump (command-line binary)
Add or remove MySQL with Ansible databases
|Specify a config file from which user and password are to be read.|
|The connection timeout when connecting to the MySQL server.|
added in 2.7
|A list of table names that will be ignored in the dump of the form database_name.table_name|
|Host running the database.|
|The password used to authenticate with.|
|Port of the MySQL server. Requires login_host|
to be defined as other than localhost if login_port is used.
|The path to a Unix domain socket for local connections.|
|The username used to authenticate with.|
|The option used for dumping large tables|
|Execute the dump in a single transaction|
|The database state|
- name: Create a new database with name 'bobdata' mysql_db: name: bobdata state: present - name: Create new databases with names 'foo' and 'bar' mysql_db: name: - foo - bar state: present # Copy the database dump file to the remote host and restore it to database 'my_db.' - name: Copy database dump file copy: src: dump.sql.bz2 dest: /tmp - name: Restore database mysql_db: name: my_db state: import target: /tmp/dump.sql.bz2 - name: Dump multiple databases mysql_db: state: dump name: db_1,db_2 target: /tmp/dump.sql - name: Dump multiple databases mysql_db: state: dump name: - db_1 - db_2 target: /tmp/dump.sql - name: Dump all databases to hostname.sql mysql_db: state: dump name: all target: /tmp/dump.sql - name: Import file.sql similar to mysql -u <username> -p <password> < hostname.sql mysql_db: state: import name: all target: /tmp/dump.sql - name: Delete database with name 'bobdata' mysql_db: name: bobdata state: absent - name: Make sure there is neither a database with the word 'foo nor one with the name 'bar.' mysql_db: name: - foo - bar state: absent