extras/ansible/roles/database/tasks/main.yml
---
- name: Install MySQL Python client
apt: name=python-mysqldb state=latest
- name: Install MariaDB
apt: name={{ item }} state=latest
with_items:
- mariadb-server
register: mariadb_install
ignore_errors: True
- name: Install MySQL if not MariaDB
apt: name=mysql-server state=latest
when: "'failed' in mariadb_install"
- name: Start MariaDB
action: service name=mysql state=started
- name: Configuring root user (if not made)
mysql_user: name=root host={{ item }} password={{ root_db_password }} priv=*.*:ALL,GRANT
with_items:
- 127.0.0.1
- ::1
- localhost
ignore_errors: True
- name: Create root .my.cnf
template: src=my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600
- name: Create myblog database
mysql_db: name=myblog state=present
- name: Bind server to address
lineinfile: regexp='^bind-address\s*=' line="bind-address = {{ mysql_bind_addr }}"
dest=/etc/mysql/my.cnf
notify: restart mysql
- mysql_user: name=myblog host={{ hostvars[item].mysql_client_addr }} password={{ db_password }} priv=myblog.*:ALL state=present
with_items: (groups.get('middleware', []) + groups.get('all', []))