ansible-mysql/tasks/main.yml

72 lines
1.7 KiB
YAML

---
- name: INCLUDE_VARS | Related to OS version
include_vars: "{{ ansible_distribution }}.yml"
- name: STAT | Check if mysql exists
stat:
path: /usr/sbin/mysqld
register: mariadb_exists
changed_when: false
- name: INCLUDE | Install
import_tasks: install/main.yml
- name: TEMPLATE | Deploy config files
template:
src: "{{ item }}"
dest: "/{{ item | replace('.j2', '') }}"
mode: 0644
owner: root
group: root
register: config
loop:
- etc/mysql/my.cnf
- etc/mysql/conf.d/mysqldump.cnf.j2
- etc/mysql/mariadb.conf.d/10-extra.cnf.j2
- etc/mysql/mariadb.conf.d/50-client.cnf.j2
- etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf.j2
- etc/mysql/mariadb.conf.d/50-server.cnf.j2
- name: SERVICE | Restart Mariadb now one at a time (prevent bugs)
throttle: 1
service:
name: mariadb
state: restarted
when:
config.changed and
not mariadb_galera_resetup
- name: SERVICE | Ensure service is started
service:
name: mariadb
state: started
- name: INCLUDE | Galera
import_tasks: galera/main.yml
when: mariadb_use_galera
- name: INCLUDE | Replication
import_tasks: replication/main.yml
when: mariadb_replication_master or mariadb_replication_slave
- name: INCLUDE | Secure install
import_tasks: 'secure.yml'
- name: MYSQL_DB | Create databases
mysql_db:
name: "{{ item }}"
state: present
loop: "{{ mariadb_databases }}"
- name: MYSQL_USER | Manages users...
mysql_user:
name: "{{ item.name }}"
password: "{{ item.password }}"
priv: "{{ item.priv }}"
host: "{{ item.host | default(omit) }}"
host_all: "{{ item.host_all | default(omit) }}"
state: present
loop: "{{ mariadb_users }}"
no_log: "{{ not mariadb_debug_role }}"