ansible-mysql/tasks/main.yml

89 lines
2.1 KiB
YAML

---
- block:
- name: SET_FACT | Bypass https://github.com/ansible/ansible/issues/19874
set_fact:
ansible_distribution_release: 'buster'
when: ansible_facts.distribution_major_version == "buster/sid"
- name: INCLUDE_VARS | Related to OS version
include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.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 configuration
template:
src: "{{ mariadb_config_template }}"
dest: /etc/mysql/my.cnf
register: config
- name: TEMPLATE | Deploy extra configuration
template:
src: etc/mysql/conf.d/10-extra.cnf.j2
dest: /etc/mysql/conf.d/10-extra.cnf
register: extraconfig
- name: SERVICE | Restart now (prevent bugs)
service:
name: mysql
state: restarted
when:
(config.changed or extraconfig.changed) and
not mariadb_galera_resetup
- name: TEMPLATE Create .my.cnf for root
template:
src: root/my.cnf
dest: /root/.my.cnf
owner: root
group: root
mode: 0600
backup: yes
- 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: SERVICE | Ensure service is started
service:
name: mysql
state: started
- 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 }}"
- name: TEMPLATE | Deploy logrotate configuration
template:
src: "etc/logrotate.d/mysql-server.j2"
dest: "/etc/logrotate.d/mysql-server"
when: mariadb_manage_logrotate | bool