diff --git a/roles/mariadb/tasks/main.yml b/roles/mariadb/tasks/main.yml index 3416a18..6271d7e 100644 --- a/roles/mariadb/tasks/main.yml +++ b/roles/mariadb/tasks/main.yml @@ -11,9 +11,9 @@ state: directory mode: 0777 with_items: - - /srv/mariadb/lib/mysql - - /srv/mariadb/etc/mysql - - /srv/mariadb/etc/mysql/conf.d + - /srv/mariadb/lib/mysql + - /srv/mariadb/etc/mysql + - /srv/mariadb/etc/mysql/conf.d - name: place settings file copy: @@ -21,12 +21,14 @@ dest: /srv/mariadb/etc/mysql/conf.d/my.cnf mode: 660 -- name: Set galara.cnf on node if we have at least three nodes. +- name: > + Set galara.cnf on node if we have at least three nodes. + And we're part of the cluster. template: src: files/galera.cnf dest: /srv/mariadb/etc/mysql/conf.d/galera.cnf mode: 660 - when: groups['databases'] | length >= 3 + when: "'databases' in group_names and groups['databases'] | length >= 3" # This mimics galera_new_cluster.sh - name: Initialize a new cluster. @@ -47,7 +49,8 @@ name: mysql.service state: started - when: groups['databases'] | length >= 3 and ansible_hostname == hostname_node0 + when: "'databases' in group_names and groups['databases'] \ + | length >= 3 and ansible_hostname == hostname_node0" - name: install service file. block: @@ -61,12 +64,22 @@ group: root - name: Give the master node some time to initialize the cluster. - command: bash -c "sleep 60 && systemctl daemon-reload" + command: bash -c "sleep 60" + when: "'databases' in group_names and groups['databases'] \ + | length >= 3" + +- name: Daemon reload (the implicit doesn't work) + command: bash -c "systemctl daemon-reload" - name: make sure service is started systemd: name: mysql.service state: started + daemon_reload: yes - name: start service at boot. command: systemctl reenable mysql.service + +- name: Give the cluster some time to initialize replication. + command: bash -c "sleep 60 && systemctl daemon-reload" + when: "'databases' in group_names and groups['databases'] | length >= 3"