77 lines
2 KiB
YAML
77 lines
2 KiB
YAML
|
---
|
||
|
# file: roles/mariadb_cluster/tasks/main.yml
|
||
|
|
||
|
- name: Create variable of other members IPs to be included into the cluster
|
||
|
set_fact: nodelist={%for host in groups['mariadb_cluster']|difference([inventory_hostname])%}{{hostvars[host].ansible_host}}{% if not loop.last %},{% endif %}{% endfor %}
|
||
|
|
||
|
- name: Install prereq packages
|
||
|
package:
|
||
|
name:
|
||
|
- mariadb-server-galera
|
||
|
- mariadb-server
|
||
|
- galera
|
||
|
state: latest
|
||
|
|
||
|
- name: Update galera config
|
||
|
template:
|
||
|
src: "galera.cnf.j2"
|
||
|
dest: "/etc/my.cnf.d/galera.cnf"
|
||
|
notify: Bootstrap Galera
|
||
|
|
||
|
- name: Enable firewall rule for MySQL access
|
||
|
firewalld:
|
||
|
port: 3306/tcp
|
||
|
permanent: yes
|
||
|
immediate: yes
|
||
|
state: enabled
|
||
|
notify: Reload firewalld
|
||
|
when: mariadb_cluster_access_ip == ""
|
||
|
|
||
|
- name: "Enable firewall rule for MySQL access to Access IP"
|
||
|
firewalld:
|
||
|
rich_rule: 'rule family="ipv4" source address="{{ mariadb_cluster_access_ip }}" port port="3306" protocol="tcp" accept'
|
||
|
permanent: yes
|
||
|
state: enabled
|
||
|
immediate: yes
|
||
|
notify: Reload firewalld
|
||
|
when: mariadb_cluster_access_ip != ""
|
||
|
|
||
|
- name: Setup access for other servers
|
||
|
include_tasks: setup-server.yml
|
||
|
loop: "{{ groups['mariadb_cluster']|difference([inventory_hostname]) }}"
|
||
|
loop_control:
|
||
|
extended: yes
|
||
|
|
||
|
- name: Place mariadb-fail script
|
||
|
template:
|
||
|
src: "mariadb-fail.j2"
|
||
|
dest: "/usr/local/sbin/mariadb-fail"
|
||
|
owner: root
|
||
|
mode: 755
|
||
|
|
||
|
- name: Deploy mariadb-fail service
|
||
|
template:
|
||
|
src: mariadb-fail.service.j2
|
||
|
dest: /etc/systemd/system/mariadb-fail.service
|
||
|
notify: Daemon Reload
|
||
|
|
||
|
- name: Create directory for mariadb override
|
||
|
file:
|
||
|
path: "/etc/systemd/system/mariadb.service.d"
|
||
|
state: directory
|
||
|
|
||
|
- name: Deploy mariadb override
|
||
|
template:
|
||
|
src: mariadb-override.conf.j2
|
||
|
dest: /etc/systemd/system/mariadb.service.d/override.conf
|
||
|
notify: Daemon Reload
|
||
|
|
||
|
- name: Flush handlers
|
||
|
meta: flush_handlers
|
||
|
|
||
|
- name: Start and enable mariadb
|
||
|
service:
|
||
|
name: mariadb
|
||
|
state: started
|
||
|
enabled: yes
|