2015-07-12 15:42:46 +07:00
|
|
|
---
|
|
|
|
|
2021-09-02 23:17:54 +07:00
|
|
|
- name: INCLUDE_VARS | Extra variables
|
|
|
|
ansible.builtin.include_vars: "{{ lookup('first_found', params) }}"
|
|
|
|
vars:
|
|
|
|
params:
|
|
|
|
files:
|
|
|
|
- '{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml'
|
|
|
|
- default.yml
|
|
|
|
paths:
|
|
|
|
- 'vars'
|
2017-06-28 21:15:44 +07:00
|
|
|
|
2015-07-12 15:42:46 +07:00
|
|
|
- name: STAT | Check if mysql exists
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.stat:
|
2018-03-18 01:00:21 +07:00
|
|
|
path: /usr/sbin/mysqld
|
2018-03-17 23:28:54 +07:00
|
|
|
register: mariadb_exists
|
2015-07-12 15:42:46 +07:00
|
|
|
changed_when: false
|
|
|
|
|
2015-07-12 17:47:44 +07:00
|
|
|
- name: INCLUDE | Install
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.import_tasks: install/main.yml
|
2015-07-12 17:47:44 +07:00
|
|
|
|
2024-08-26 22:42:14 +07:00
|
|
|
- name: SHELL | Get current mariadb version # noqa: risky-shell-pipe
|
2024-08-26 21:48:03 +07:00
|
|
|
ansible.builtin.shell: dpkg -l mariadb-common | awk '/^ii/ { print $3 }' | sed -r 's/^1://g; s/^([[:digit:]]+\.[[:digit:]]+).+$/\1/g'
|
|
|
|
register: __mariadb_version
|
|
|
|
changed_when: false
|
|
|
|
|
2019-12-29 01:02:41 +07:00
|
|
|
- name: TEMPLATE | Deploy config files
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.template:
|
2019-12-29 01:02:41 +07:00
|
|
|
src: "{{ item }}"
|
|
|
|
dest: "/{{ item | replace('.j2', '') }}"
|
2021-09-02 23:17:54 +07:00
|
|
|
mode: 0644
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
register: config
|
2019-12-29 01:02:41 +07:00
|
|
|
loop:
|
|
|
|
- etc/mysql/conf.d/mysqldump.cnf.j2
|
|
|
|
- etc/mysql/mariadb.conf.d/10-extra.cnf.j2
|
|
|
|
- etc/mysql/mariadb.conf.d/50-server.cnf.j2
|
2015-08-11 04:45:01 +07:00
|
|
|
|
2024-08-26 19:47:03 +07:00
|
|
|
- name: FILE | Ensure log dir exists
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "{{ mariadb_slow_query_log_file | dirname }}"
|
|
|
|
state: directory
|
|
|
|
mode: 0755
|
|
|
|
owner: mysql
|
|
|
|
group: mysql
|
|
|
|
|
2020-06-13 17:04:18 +07:00
|
|
|
- name: SERVICE | Restart Mariadb now one at a time (prevent bugs)
|
|
|
|
throttle: 1
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.service:
|
|
|
|
name: "{{ mariadb_service_name }}"
|
2018-03-18 00:28:56 +07:00
|
|
|
state: restarted
|
2019-04-16 18:55:38 +07:00
|
|
|
when:
|
2019-12-29 01:02:41 +07:00
|
|
|
config.changed and
|
2018-03-17 23:28:54 +07:00
|
|
|
not mariadb_galera_resetup
|
2015-07-12 15:42:46 +07:00
|
|
|
|
2021-09-02 23:17:54 +07:00
|
|
|
- name: SERVICE | Ensure service is started
|
|
|
|
ansible.builtin.service:
|
|
|
|
name: "{{ mariadb_service_name }}"
|
|
|
|
state: started
|
|
|
|
|
2016-09-23 22:03:13 +07:00
|
|
|
- name: INCLUDE | Galera
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.import_tasks: galera/main.yml
|
2019-04-16 18:55:38 +07:00
|
|
|
when: mariadb_use_galera
|
2016-09-23 22:03:13 +07:00
|
|
|
|
2015-08-21 15:10:27 +07:00
|
|
|
- name: INCLUDE | Replication
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.import_tasks: replication/main.yml
|
2018-03-17 23:28:54 +07:00
|
|
|
when: mariadb_replication_master or mariadb_replication_slave
|
2015-08-08 04:34:47 +07:00
|
|
|
|
2015-07-12 15:42:46 +07:00
|
|
|
- name: INCLUDE | Secure install
|
2021-09-02 23:17:54 +07:00
|
|
|
ansible.builtin.import_tasks: 'secure.yml'
|
2017-06-01 21:26:24 +07:00
|
|
|
|
2015-07-12 15:42:46 +07:00
|
|
|
- name: MYSQL_DB | Create databases
|
2021-09-02 23:17:54 +07:00
|
|
|
community.mysql.mysql_db:
|
2018-03-18 00:28:56 +07:00
|
|
|
name: "{{ item }}"
|
|
|
|
state: present
|
2022-03-04 16:56:27 +07:00
|
|
|
login_unix_socket: "{{ mariadb_socket }}"
|
2019-04-12 14:38:42 +07:00
|
|
|
loop: "{{ mariadb_databases }}"
|
2015-07-12 15:42:46 +07:00
|
|
|
|
|
|
|
- name: MYSQL_USER | Manages users...
|
2021-09-02 23:17:54 +07:00
|
|
|
community.mysql.mysql_user:
|
2018-03-18 00:28:56 +07:00
|
|
|
name: "{{ item.name }}"
|
|
|
|
password: "{{ item.password }}"
|
|
|
|
priv: "{{ item.priv }}"
|
2019-01-25 17:42:04 +07:00
|
|
|
host: "{{ item.host | default(omit) }}"
|
|
|
|
host_all: "{{ item.host_all | default(omit) }}"
|
2018-03-18 00:28:56 +07:00
|
|
|
state: present
|
2022-03-04 16:56:27 +07:00
|
|
|
login_unix_socket: "{{ mariadb_socket }}"
|
2019-04-12 14:38:42 +07:00
|
|
|
loop: "{{ mariadb_users }}"
|
2021-09-01 17:24:40 +07:00
|
|
|
no_log: "{{ not mariadb_debug_role }}"
|