---

- name: 'Copy MySQL configuration for replication'
  ansible.builtin.template:
    src: 'replication.cnf.j2'
    dest: "{{ mysql_config_directory }}/zzzz-replication.cnf"
    mode: "0644"
  notify: 'restart mysql'

- name: 'Create repl user'
  community.mysql.mysql_user:
    name: 'repl'
    host: '%'
    encrypted: true
    password: "{{ mysql_repl_password }}"
    priv: '*.*:REPLICATION SLAVE,REPLICATION CLIENT'
    update_password: 'on_create'
    state: 'present'
  register: create_repl_user
  when: mysql_repl_password | length > 0

- name: 'Install xinetd'
  ansible.builtin.apt:
    name: 'xinetd'

- name: 'Add xinetd configuration for MySQL HAProxy check'
  ansible.builtin.copy:
    src: 'xinetd/mysqlchk'
    dest: '/etc/xinetd.d/'
    mode: '0644'
  notify: 'restart xinetd'

# /!\ Warning, this is a temporary hack
- ansible.builtin.include_role:
    name: remount-usr

- name: 'Copy mysqlchk script'
  ansible.builtin.copy:
    src: 'xinetd/mysqlchk.sh'
    dest: '/usr/share/scripts/'
    mode: '0755'
