🚀 Manage Galera
parent
cdfd71ce76
commit
c32411c6e4
|
@ -14,6 +14,7 @@ jobs:
|
|||
fail-fast: false
|
||||
matrix:
|
||||
scenario:
|
||||
- debian12_galera
|
||||
- debian12_master_slave
|
||||
- debian12_upstream
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ mariadb_upstream_version: '11.4'
|
|||
# Galera
|
||||
# -------------------------------------
|
||||
mariadb_galera_resetup: false
|
||||
mariadb_wsrep_node_address: false # Set primary node IP
|
||||
mariadb_wsrep_node_address: '{{ ansible_default_ipv4.address if ansible_default_ipv4 is defined else "127.0.0.1" }}'
|
||||
mariadb_galera_members: []
|
||||
mariadb_galera_primary_node: 'change_me' # See: https://github.com/ansible/ansible/issues/17453
|
||||
mariadb_wsrep_sst_method: 'rsync'
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
name: "{{ mariadb_service_name }}"
|
||||
state: restarted
|
||||
when: mariadb_notify_restart
|
||||
throttle: 1
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
mariadb_use_galera: true
|
||||
mariadb_galera_members: "{{ groups['galera'] }}"
|
||||
mariadb_galera_primary_node: "{{ mariadb_galera_members | first }}"
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
|
||||
- name: Converge
|
||||
hosts: all
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Include role
|
||||
ansible.builtin.include_role:
|
||||
name: "hanxhx.mysql"
|
|
@ -0,0 +1,55 @@
|
|||
---
|
||||
|
||||
platforms:
|
||||
- name: debian12-galera1
|
||||
image: dokken/debian-12
|
||||
command: /lib/systemd/systemd
|
||||
dockerfile: ../_shared/Dockerfile.j2
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
privileged: true
|
||||
groups:
|
||||
- galera
|
||||
networks:
|
||||
- name: "00-molecule-d12-galera"
|
||||
ipv4_address: '172.16.51.1'
|
||||
docker_networks:
|
||||
- name: "00-molecule-d12-galera"
|
||||
ipam_config:
|
||||
- subnet: "172.16.51.0/24"
|
||||
gateway: "172.16.51.254"
|
||||
|
||||
- name: debian12-galera2
|
||||
image: dokken/debian-12
|
||||
command: /lib/systemd/systemd
|
||||
dockerfile: ../_shared/Dockerfile.j2
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
privileged: true
|
||||
groups:
|
||||
- galera
|
||||
networks:
|
||||
- name: "00-molecule-d12-galera"
|
||||
ipv4_address: '172.16.51.2'
|
||||
|
||||
- name: debian12-galera3
|
||||
image: dokken/debian-12
|
||||
command: /lib/systemd/systemd
|
||||
dockerfile: ../_shared/Dockerfile.j2
|
||||
capabilities:
|
||||
- SYS_ADMIN
|
||||
cgroupns_mode: host
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:rw
|
||||
privileged: true
|
||||
groups:
|
||||
- galera
|
||||
networks:
|
||||
- name: "00-molecule-d12-galera"
|
||||
ipv4_address: '172.16.51.3'
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
|
||||
- name: Verify Galera
|
||||
hosts: galera
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: MYSQL_QUERY | Check if Galera is running
|
||||
community.mysql.mysql_query:
|
||||
query: "SHOW GLOBAL STATUS LIKE 'wsrep_ready'"
|
||||
login_unix_socket: /run/mysqld/mysqld.sock
|
||||
register: wsrep_ready
|
||||
|
||||
- name: ASSERT | Fail if Galera is not running
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wsrep_ready.query_result.0.0.Value == "ON"
|
||||
fail_msg: "Galera is not running"
|
||||
success_msg: "Galera is running"
|
||||
|
||||
- name: MYSQL_QUERY | Check Galera status
|
||||
community.mysql.mysql_query:
|
||||
query: "SHOW GLOBAL STATUS LIKE 'wsrep_local_state_comment'"
|
||||
login_unix_socket: /run/mysqld/mysqld.sock
|
||||
register: wsrep_local_state_comment
|
||||
|
||||
- name: ASSERT | Fail if Galera is not on the right state
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- wsrep_local_state_comment.query_result.0.0.Value == "Synced"
|
||||
fail_msg: "Galera is not expected state ({{ wsrep_local_state_comment.query_result.0.0.Value }})"
|
||||
success_msg: "Galera is in expected state"
|
|
@ -1,4 +1,5 @@
|
|||
---
|
||||
|
||||
- name: SET_FACT | Prepare mark var
|
||||
ansible.builtin.set_fact:
|
||||
__mark: "{{ mariadb_datadir }}/.ansible_galera_boostrap"
|
||||
|
|
|
@ -2,31 +2,20 @@
|
|||
|
||||
- name: APT | Install Galera
|
||||
ansible.builtin.apt:
|
||||
pkg: "{{ mariadb_galera_package_name }}"
|
||||
name: "{{ mariadb_galera_package_name }}"
|
||||
|
||||
- name: TEMPLATE | Deploy Galera configuration
|
||||
ansible.builtin.template:
|
||||
src: etc/mysql/mariadb.conf.d/20-galera.cnf.j2
|
||||
dest: /etc/mysql/mariadb.conf.d/20-galera.cnf
|
||||
src: etc/mysql/mariadb.conf.d/60-galera.cnf.j2
|
||||
dest: /etc/mysql/mariadb.conf.d/60-galera.cnf
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: root
|
||||
register: galeraconfig
|
||||
notify: Restart mariadb
|
||||
|
||||
- name: INCLUDE | Bootstrap first node
|
||||
ansible.builtin.import_tasks: 'bootstrap.yml'
|
||||
when: inventory_hostname == mariadb_galera_primary_node
|
||||
|
||||
- name: INCLUDE | Configure other nodes
|
||||
ansible.builtin.import_tasks: 'nodes.yml'
|
||||
when: inventory_hostname != mariadb_galera_primary_node
|
||||
|
||||
- name: SERVICE | Restart MariaDB if needed
|
||||
ansible.builtin.service:
|
||||
name: "{{ mariadb_service_name }}"
|
||||
state: restarted
|
||||
when:
|
||||
((galeraconfig or (p is defined and p.changed)) and
|
||||
(bootstrap_run is not defined)) or
|
||||
((inventory_hostname != mariadb_galera_primary_node) and
|
||||
(mariadb_galera_resetup))
|
||||
- name: META | Flush handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
---
|
||||
|
||||
- name: COMMAND | GET debian.cnf from primary node
|
||||
ansible.builtin.command: cat /etc/mysql/debian.cnf
|
||||
register: debiancnf
|
||||
delegate_to: '{{ mariadb_galera_primary_node }}'
|
||||
changed_when: false
|
||||
|
||||
- name: COMMAND | Get current debian.cnf
|
||||
ansible.builtin.command: cat /etc/mysql/debian.cnf
|
||||
register: ondc
|
||||
changed_when: false
|
||||
|
||||
- name: BLOCK | Compare debian.cnf
|
||||
when: debiancnf.stdout != ondc.stdout
|
||||
block:
|
||||
|
||||
- name: SERVICE | Stop MariaDB
|
||||
ansible.builtin.service:
|
||||
name: "{{ mariadb_service_name }}"
|
||||
state: stopped
|
||||
|
||||
- name: COPY | Paste primary node's debian.cnf
|
||||
ansible.builtin.copy:
|
||||
content: "{{ debiancnf.stdout }}"
|
||||
dest: /etc/mysql/debian.cnf
|
||||
mode: 0600
|
||||
owner: root
|
||||
group: root
|
||||
register: paste
|
||||
|
||||
- name: SERVICE | Start MariaDB
|
||||
ansible.builtin.service:
|
||||
name: "{{ mariadb_service_name }}"
|
||||
state: started
|
|
@ -36,6 +36,7 @@
|
|||
- 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
|
||||
notify: Restart mariadb
|
||||
|
||||
- name: FILE | Ensure log dir exists
|
||||
ansible.builtin.file:
|
||||
|
@ -45,14 +46,8 @@
|
|||
owner: mysql
|
||||
group: mysql
|
||||
|
||||
- name: SERVICE | Restart Mariadb now one at a time (prevent bugs)
|
||||
throttle: 1
|
||||
ansible.builtin.service:
|
||||
name: "{{ mariadb_service_name }}"
|
||||
state: restarted
|
||||
when:
|
||||
config.changed and
|
||||
not mariadb_galera_resetup
|
||||
- name: META | Flush handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
||||
- name: SERVICE | Ensure service is started
|
||||
ansible.builtin.service:
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
# Global
|
||||
wsrep_on = ON
|
||||
wsrep_provider = /usr/lib/galera/libgalera_smm.so
|
||||
wsrep_cluster_address = gcomm://{{ mariadb_galera_members | join(",") }}
|
||||
wsrep_sst_method = "{{ mariadb_wsrep_sst_method }}"
|
||||
{% if mariadb_wsrep_cluster_name is defined %}
|
||||
|
@ -19,7 +20,7 @@ wsrep_cluster_name = "{{ mariadb_wsrep_cluster_name }}"
|
|||
{% endif %}
|
||||
|
||||
# Node Configuration
|
||||
wsrep_node_address = "{{ mariadb_wsrep_node_address | default(ansible_default_ipv4.address if ansible_default_ipv4 is defined else '127.0.0.1') }}"
|
||||
wsrep_node_address = "{{ mariadb_wsrep_node_address }}"
|
||||
wsrep_node_name = "{{ mariadb_wsrep_node_name | default(ansible_fqdn) }}"
|
||||
|
||||
# Deps
|
||||
|
|
Loading…
Reference in New Issue