Skip to content

Instantly share code, notes, and snippets.

@Kahn
Last active December 22, 2015 06:59
Show Gist options
  • Save Kahn/6435303 to your computer and use it in GitHub Desktop.
Save Kahn/6435303 to your computer and use it in GitHub Desktop.
Ansible MySQL database setup
# config
/etc/ansible/host_vars/dbserver
---
dbs_inst: ['testdb1', 'testdb2']
dbs:
- { name: 'testdb1', password: 'password1', priv: 'testdb1.*:ALL' }
- { name: 'testdb2', password: 'password2', priv: 'testdb2.*:SELECT' }
/etc/ansible/roles/mysql/tasks/main.yml
...
- name: create additional MySQL databases
action: mysql_db db={{ item.name }} state=present
with_items: dbs
tags:
- config
- mysql
- name: create additional MySQL users
action: mysql_user name={{ item.name }} password={{ item.password }} priv={{ item.priv }} state=present
with_items: dbs
tags:
- config
- mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment