From c5c577518da5e64f7529dc1d557a74199df0b30c Mon Sep 17 00:00:00 2001 From: git-harry Date: Tue, 14 Apr 2015 16:16:25 +0100 Subject: [PATCH] Fix conditional galera restarts The task files galera_add_node.yml and galera_bootstrap.yml in the galera_server role both restart mysql based on conditions. These conditions are incorrectly defined causing restarts to happen every time . This commit addresses several issues related to how these conditions are defined and compared. - The the pgrep pattern for the task 'Check if mysql is running' has been modified so that is no longer matches the ansible shell command. It also ignores errors generated by pgrep failing to find a match so that it can be used by other tasks. - The registered variables, used by the when clauses, have appropriately defined changed attributes. This commit modifies the when clauses to make use of them. - The when clause for the tasks 'bootstrap cluster (initialise mysql with --wsrep-new-cluster)' and 'Restart mysql' were always being met because 'mysql_running != 0' should be 'mysql_running.rc != 0', they has been adjusted to use the changed status. Closes-bug: #1444308 Change-Id: Ib2879bfe9754575fd984a1f1d132d5a42b848e21 --- .../roles/galera_server/tasks/galera_add_node.yml | 7 +++---- .../roles/galera_server/tasks/galera_bootstrap.yml | 14 ++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/playbooks/roles/galera_server/tasks/galera_add_node.yml b/playbooks/roles/galera_server/tasks/galera_add_node.yml index d9c977aea9..e97d22e21e 100644 --- a/playbooks/roles/galera_server/tasks/galera_add_node.yml +++ b/playbooks/roles/galera_server/tasks/galera_add_node.yml @@ -14,9 +14,10 @@ # limitations under the License. - name: Check if mysql is running - shell: "pgrep -fl mysqld" + shell: "pgrep -fl [m]ysqld" register: mysql_running changed_when: mysql_running.rc != 0 + ignore_errors: True tags: - galera-bootstrap @@ -33,9 +34,7 @@ service: name: mysql state: restarted - when: > - "not wsrep_incoming_addresses.stdout|search('{{ ansible_ssh_host }}')" or - mysql_running != 0 + when: wsrep_incoming_addresses|changed or mysql_running|changed tags: - galera-add-node - galera-bootstrap diff --git a/playbooks/roles/galera_server/tasks/galera_bootstrap.yml b/playbooks/roles/galera_server/tasks/galera_bootstrap.yml index 7460c31fe6..f58fe86b4c 100644 --- a/playbooks/roles/galera_server/tasks/galera_bootstrap.yml +++ b/playbooks/roles/galera_server/tasks/galera_bootstrap.yml @@ -14,9 +14,10 @@ # limitations under the License. - name: Check if mysql is running - shell: "pgrep -fl mysqld" + shell: "pgrep -fl [m]ysqld" register: mysql_running changed_when: mysql_running.rc != 0 + ignore_errors: True tags: - galera-bootstrap @@ -25,7 +26,7 @@ mysql -e 'show status like "wsrep_cluster_size%"\G'|awk '/Value/{print $2}' register: wsrep_cluster_size changed_when: wsrep_cluster_size.stdout|search("1") - when: mysql_running.rc == 0 + when: not mysql_running|changed tags: - galera-bootstrap @@ -36,15 +37,16 @@ pattern: mysqld register: mysqlstopped when: > - mysql_running.rc == 0 and - (wsrep_cluster_size.stdout | search("1") or wsrep_cluster_size.stderr | search("ERROR")) + (not mysql_running|changed) and + (wsrep_cluster_size|changed or wsrep_cluster_size.stderr | search("ERROR")) tags: - galera-bootstrap - name: Check if mysql is running - shell: "pgrep -fl mysqld" + shell: "pgrep -fl [m]ysqld" register: mysql_running changed_when: mysql_running.rc != 0 + ignore_errors: True tags: - galera-bootstrap @@ -53,6 +55,6 @@ name: mysql state: restarted args: --wsrep-new-cluster - when: wsrep_cluster_size.stdout|search("1") or mysqlstopped|changed or mysql_running != 0 + when: wsrep_cluster_size|changed or mysqlstopped|changed or mysql_running|changed tags: - galera-bootstrap