---
- name: Get MySQL version.
  command: 'mysql --version'
  register: mysql_cli_version
  changed_when: false
  check_mode: false

- name: Setup Mariadb config file
  template:
    src: server.j2
    dest: "{{ mariadb_config_file }}"
    owner: "{{ mariadb_config_file_owner }}"
    group: "{{ mariadb_config_file_group }}"
    mode: 0644

- name: Setup Galera config file if needed
  template:
    src: galera.j2
    dest: "{{ galera_config_file }}"
    owner: "{{ mariadb_config_file_owner }}"
    group: "{{ mariadb_config_file_group }}"
    mode: 0644
  when: (nb_db_servers | int) > 1

- name: Synchronize mariadb_datadir if custom path
  synchronize:
    src: /var/lib/mysql/
    dest: "{{ mariadb_datadir }}"
  delegate_to: "{{ inventory_hostname }}"
  when: mariadb_datadir != "/var/lib/mysql"

- name: Mariadb service
  service:
    name: "{{ mariadb_service }}"
    state: started
    enabled: yes 
