From 1ef196baddbe5d681ac10ee23e01c5f0ac8bed79 Mon Sep 17 00:00:00 2001 From: "carey.xu" Date: Tue, 1 Mar 2016 16:44:00 +0800 Subject: maker rabbitmq playbook reentrant JIRA: COMPASS-328 Change-Id: Ia859db4f995ffac4cf01ab74da17f51c5d84dd1f Signed-off-by: carey.xu --- .../ansible/roles/mq/tasks/rabbitmq_cluster.yml | 17 ++++++++++++++++- .../ansible/roles/mq/tasks/rabbitmq_install.yml | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'deploy/adapters/ansible/roles') diff --git a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml index a84cbeda..50c062f5 100644 --- a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml +++ b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml @@ -7,15 +7,30 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## --- +- name: check if i in the node list + shell: | + rabbitmqctl -q cluster_status | grep '\[{nodes,'|grep {{ inventory_hostname }} + changed_when: is_member.rc != 0 + failed_when: false + register: is_member + delegate_to: '{{ haproxy_hosts.keys()[0] }}' + - name: stop rabbitmq app - shell: rabbitmqctl stop_app; sleep 3 + shell: | + rabbitmqctl stop_app; sleep 5 + failed_when: false + when: is_member.rc != 0 - name: join cluster shell: rabbitmqctl join_cluster rabbit@{{ haproxy_hosts.keys()[0] }} register: join_result + when: is_member.rc != 0 until: join_result|success + failed_when: join_result|failed and not 'already_member' in join_result.stderr + changed_when: join_result|success retries: 20 delay: 3 - name: start rabbitmq app shell: rabbitmqctl start_app + when: is_member.rc != 0 diff --git a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml index 067e240e..1c8c2fe7 100755 --- a/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml +++ b/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_install.yml @@ -68,6 +68,21 @@ pattern: '^(?!amq\.).*' tags: "ha-mode=all" +- name: get cluster name + shell: | + rabbitmqctl cluster_status | grep -w '<<"compass">>' + register: cluster_status + failed_when: false + changed_when: cluster_status.rc != 0 + when: | + inventory_hostname == haproxy_hosts.keys()[0] + +- name: set cluster name + shell: rabbitmqctl set_cluster_name compass + when: | + inventory_hostname == haproxy_hosts.keys()[0] + and cluster_status.rc != 0 + - include: rabbitmq_cluster.yml when: inventory_hostname != haproxy_hosts.keys()[0] -- cgit 1.2.3-korg