68 lines
2.0 KiB
YAML
68 lines
2.0 KiB
YAML
|
---
|
||
|
- name: Write config
|
||
|
ansible.builtin.template:
|
||
|
src: "mysql.cnf.j2"
|
||
|
dest: "/etc/mysql/mariadb.conf.d/50-server.cnf"
|
||
|
mode: "0644"
|
||
|
become: true
|
||
|
|
||
|
- name: restart mysql
|
||
|
ansible.builtin.service:
|
||
|
name: mysql
|
||
|
state: restarted
|
||
|
enabled: true
|
||
|
become: true
|
||
|
|
||
|
- name: Create replication user
|
||
|
community.mysql.mysql_user:
|
||
|
state: present
|
||
|
login_user: root
|
||
|
login_password: "{{ mysql_root_password }}"
|
||
|
name: "{{ mysql.replication_user }}"
|
||
|
password: "{{ mysql_replication_pass }}"
|
||
|
host: "%"
|
||
|
tls_requires:
|
||
|
priv:
|
||
|
"*.*": "REPLICATION SLAVE"
|
||
|
login_unix_socket: /var/run/mysqld/mysqld.sock
|
||
|
become: true
|
||
|
when: mysql.replication_master in ansible_all_ipv4_addresses
|
||
|
|
||
|
- name: Get master replication status
|
||
|
community.mysql.mysql_replication:
|
||
|
login_user: root
|
||
|
login_password: "{{ mysql_root_password }}"
|
||
|
mode: getmaster
|
||
|
register: repl_stat
|
||
|
when: ansible_hostname == mysql.replication_master
|
||
|
|
||
|
- debug: var=repl_stat
|
||
|
|
||
|
- name: Check if slave is already configured as replica
|
||
|
community.mysql.mysql_replication:
|
||
|
login_user: root
|
||
|
login_password: "{{ mysql_root_password }}"
|
||
|
mode: getslave
|
||
|
ignore_errors: true
|
||
|
register: slave
|
||
|
when: ansible_hostname in mysql.replication_slaves
|
||
|
|
||
|
- name: Setup slaves
|
||
|
community.mysql.mysql_replication:
|
||
|
login_user: root
|
||
|
login_password: "{{ mysql_root_password }}"
|
||
|
mode: changemaster
|
||
|
master_host: "{{ mysql.replication_master }}"
|
||
|
master_log_file: "{{ hostvars['web1'].repl_stat.File }}"
|
||
|
master_log_pos: "{{ hostvars['web1'].repl_stat.Position }}"
|
||
|
master_user: "{{ mysql.replication_user }}"
|
||
|
master_password: "{{ mysql_replication_pass }}"
|
||
|
when: ansible_hostname in mysql.replication_slaves and not slave.Is_Slave
|
||
|
|
||
|
- name: Start slave replication
|
||
|
community.mysql.mysql_replication:
|
||
|
login_user: root
|
||
|
login_password: "{{ mysql_root_password }}"
|
||
|
mode: startslave
|
||
|
when: ansible_hostname in mysql.replication_slaves and not slave.Is_Slave
|