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: ansible_hostname == mysql.replication_master_hostname
- 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_hostname
- 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_ip }}"
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