mirror of
https://github.com/HanXHX/ansible-mysql.git
synced 2026-02-24 10:13:30 +07:00
[GALERA] Install and configuration: first and other nodes
This commit is contained in:
23
tasks/galera/bootstrap.yml
Normal file
23
tasks/galera/bootstrap.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
- set_fact:
|
||||
booboo: /var/lib/mysql/.ansible_galera_boostrap
|
||||
|
||||
- name: STAT | Bootstrap mark
|
||||
stat: path={{ booboo }}
|
||||
register: s
|
||||
|
||||
- block:
|
||||
|
||||
- name: COMMAND | Stop MariaDB
|
||||
service: name=mysql state=stopped
|
||||
|
||||
- name: COMMAND | Bootstrap first node
|
||||
command: galera_new_cluster
|
||||
register: bootstrap_run
|
||||
|
||||
when: not s.stat.exists
|
||||
|
||||
- name: COMMAND | Create Bootstrap mark
|
||||
command: "touch {{ booboo }}"
|
||||
args:
|
||||
creates: "{{ booboo }}"
|
||||
19
tasks/galera/main.yml
Normal file
19
tasks/galera/main.yml
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
|
||||
- name: TEMPLATE | Deploy Galera configuration
|
||||
template: src=etc/mysql/conf.d/09-galera.cnf.j2 dest=/etc/mysql/conf.d/09-galera.cnf
|
||||
register: galeraconfig
|
||||
|
||||
- name: INCLUDE | Bootstrap first node
|
||||
include: 'bootstrap.yml'
|
||||
when: inventory_hostname == mysql_galera_primary_node
|
||||
|
||||
- name: INCLUDE | Configure other nodes
|
||||
include: 'nodes.yml'
|
||||
when: inventory_hostname != mysql_galera_primary_node
|
||||
|
||||
- name: SERVICE | Restart MariaDB if needed
|
||||
service: name=mysql state=restarted
|
||||
when: >
|
||||
(galeraconfig or (p is defined and p.changed)) and
|
||||
(bootstrap_run is not defined)
|
||||
29
tasks/galera/nodes.yml
Normal file
29
tasks/galera/nodes.yml
Normal file
@@ -0,0 +1,29 @@
|
||||
---
|
||||
|
||||
- name: COMMAND | GET debian.cnf from primary node
|
||||
command: cat /etc/mysql/debian.cnf
|
||||
register: debiancnf
|
||||
delegate_to: '{{ mysql_galera_primary_node }}'
|
||||
|
||||
- name: COMMAND | Get current debian.cnf
|
||||
command: cat /etc/mysql/debian.cnf
|
||||
register: ondc
|
||||
|
||||
- block:
|
||||
|
||||
- name: SERVICE | Stop MariaDB
|
||||
service: name=mysql state=stopped
|
||||
|
||||
- name: COPY | Paste primary node's debian.cnf
|
||||
copy: >
|
||||
content={{ debiancnf.stdout }}
|
||||
dest=/etc/mysql/debian.cnf
|
||||
mode=0600
|
||||
owner=root
|
||||
group=root
|
||||
register: paste
|
||||
|
||||
- name: SERVICE | Start MariaDB
|
||||
service: name=mysql state=started
|
||||
|
||||
when: debiancnf.stdout != ondc.stdout
|
||||
Reference in New Issue
Block a user