67 lines
1.6 KiB
YAML
67 lines
1.6 KiB
YAML
# Install a docker based mariadb.
|
|
---
|
|
- name: include secrets
|
|
include_vars:
|
|
file: ../../secrets.yml
|
|
name: secrets
|
|
|
|
- name: install service file.
|
|
template:
|
|
src: templates/mysql.service
|
|
dest: /etc/systemd/system/mysql.service
|
|
mode: 644
|
|
owner: root
|
|
group: root
|
|
|
|
- name: make mariadb settings volume
|
|
file:
|
|
path: "{{ item }}"
|
|
state: directory
|
|
mode: 0777
|
|
with_items:
|
|
- /srv/mariadb/lib/mysql
|
|
- /srv/mariadb/etc/mysql
|
|
- /srv/mariadb/etc/mysql/conf.d
|
|
|
|
- name: place settings file
|
|
copy:
|
|
src: files/my.cnf
|
|
dest: /srv/mariadb/etc/mysql/conf.d/my.cnf
|
|
mode: 660
|
|
|
|
- name: Set galara.cnf on node if we have at least three nodes.
|
|
template:
|
|
src: files/galera.cnf
|
|
dest: /srv/mariadb/etc/mysql/conf.d/galera.cnf
|
|
mode: 660
|
|
when: groups['databases'] | length >= 3
|
|
|
|
- command: systemctl daemon-reload
|
|
|
|
- name: start service at boot.
|
|
command: systemctl reenable mysql.service
|
|
|
|
- name: create environment file for systemd
|
|
copy:
|
|
content: ""
|
|
dest: /srv/mariadb/systemd_environment
|
|
mode: 0644
|
|
|
|
# This mimics galera_new_cluster.sh
|
|
- name: Initialize a new cluster.
|
|
lineinfile:
|
|
path: /srv/mariadb/systemd_environment
|
|
line: _WSREP_NEW_CLUSTER='--wsrep-new-cluster'
|
|
when: groups['databases'] | length >= 3 and ansible_hostname == hostname_node0
|
|
|
|
- name: make sure service is started
|
|
systemd:
|
|
name: mysql.service
|
|
state: started
|
|
|
|
- name: Prevent cluster re-initialization
|
|
lineinfile:
|
|
path: /srv/mariadb/systemd_environment
|
|
state: absent
|
|
line: _WSREP_NEW_CLUSTER='--wsrep-new-cluster'
|