2017-04-25 14:47:04 +02:00
|
|
|
# Install a docker based mariadb.
|
|
|
|
---
|
2017-08-14 16:40:06 +02:00
|
|
|
- name: include secrets
|
|
|
|
include_vars:
|
|
|
|
file: ../../secrets.yml
|
|
|
|
name: secrets
|
|
|
|
|
2017-06-22 09:19:08 +02:00
|
|
|
- name: make mariadb settings volume
|
|
|
|
file:
|
2017-08-02 15:22:10 +02:00
|
|
|
path: "{{ item }}"
|
2017-06-22 09:19:08 +02:00
|
|
|
state: directory
|
|
|
|
mode: 0777
|
2017-08-02 15:22:10 +02:00
|
|
|
with_items:
|
2018-05-17 16:12:28 +02:00
|
|
|
- /srv/mariadb/lib/mysql
|
|
|
|
- /srv/mariadb/etc/mysql
|
|
|
|
- /srv/mariadb/etc/mysql/conf.d
|
2017-06-22 09:19:08 +02:00
|
|
|
|
|
|
|
- name: place settings file
|
|
|
|
copy:
|
|
|
|
src: files/my.cnf
|
2017-08-31 15:02:47 +02:00
|
|
|
dest: /srv/mariadb/etc/mysql/conf.d/my.cnf
|
2017-06-22 09:19:08 +02:00
|
|
|
mode: 660
|
|
|
|
|
2018-05-17 16:12:28 +02:00
|
|
|
- name: >
|
|
|
|
Set galara.cnf on node if we have at least three nodes.
|
|
|
|
And we're part of the cluster.
|
2017-08-31 15:02:47 +02:00
|
|
|
template:
|
|
|
|
src: files/galera.cnf
|
|
|
|
dest: /srv/mariadb/etc/mysql/conf.d/galera.cnf
|
|
|
|
mode: 660
|
2018-05-17 16:12:28 +02:00
|
|
|
when: "'databases' in group_names and groups['databases'] | length >= 3"
|
2017-08-31 15:02:47 +02:00
|
|
|
|
|
|
|
# This mimics galera_new_cluster.sh
|
|
|
|
- name: Initialize a new cluster.
|
|
|
|
block:
|
|
|
|
- set_fact:
|
|
|
|
mariadb_args: "--wsrep-new-cluster"
|
|
|
|
|
|
|
|
- template:
|
|
|
|
src: templates/mysql.service
|
|
|
|
dest: /etc/systemd/system/mysql.service
|
|
|
|
mode: 644
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- command: systemctl daemon-reload
|
|
|
|
|
|
|
|
- systemd:
|
|
|
|
name: mysql.service
|
|
|
|
state: started
|
|
|
|
|
2018-05-17 16:12:28 +02:00
|
|
|
when: "'databases' in group_names and groups['databases'] \
|
|
|
|
| length >= 3 and ansible_hostname == hostname_node0"
|
2017-08-31 15:02:47 +02:00
|
|
|
|
|
|
|
- name: install service file.
|
|
|
|
block:
|
|
|
|
- set_fact:
|
|
|
|
mariadb_args: ""
|
|
|
|
- template:
|
|
|
|
src: templates/mysql.service
|
|
|
|
dest: /etc/systemd/system/mysql.service
|
|
|
|
mode: 644
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
|
|
|
|
- name: Give the master node some time to initialize the cluster.
|
2018-05-17 16:12:28 +02:00
|
|
|
command: bash -c "sleep 60"
|
|
|
|
when: "'databases' in group_names and groups['databases'] \
|
|
|
|
| length >= 3"
|
|
|
|
|
|
|
|
- name: Daemon reload (the implicit doesn't work)
|
|
|
|
command: bash -c "systemctl daemon-reload"
|
2017-06-22 09:19:08 +02:00
|
|
|
|
2017-04-25 14:47:04 +02:00
|
|
|
- name: make sure service is started
|
|
|
|
systemd:
|
|
|
|
name: mysql.service
|
|
|
|
state: started
|
2018-05-17 16:12:28 +02:00
|
|
|
daemon_reload: yes
|
2017-08-31 15:02:47 +02:00
|
|
|
|
|
|
|
- name: start service at boot.
|
|
|
|
command: systemctl reenable mysql.service
|
2018-05-17 16:12:28 +02:00
|
|
|
|
|
|
|
- name: Give the cluster some time to initialize replication.
|
|
|
|
command: bash -c "sleep 60 && systemctl daemon-reload"
|
|
|
|
when: "'databases' in group_names and groups['databases'] | length >= 3"
|