From 3b897ad51551f47d3e11cf182c5ecfe14d3130af Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Fri, 24 Nov 2017 12:54:56 +0000 Subject: [PATCH] Create cluster without using a failed task Currently a new cluster is created by using a try/rescue operation which always fails for a new cluster, causing a lot of confusion due to the failed task report. This patch implements an improvement which tests the cluster state and creates a new one if it is not ready without requiring the task to fail. As the cluster creation is a single task, it's merged into the rabbitmq_cluster.yml task file. As the tags are all the same, the tag is set in the main task file instead of individually on all the tasks. Change-Id: Iaa8e429cbd1c539d8242453c0490373c758dd9fe --- tasks/main.yml | 1 + tasks/rabbitmq_cluster.yml | 18 ++++++++++++++++-- tasks/rabbitmq_cluster_create.yml | 28 ---------------------------- tasks/rabbitmq_cluster_join.yml | 8 -------- 4 files changed, 17 insertions(+), 38 deletions(-) delete mode 100644 tasks/rabbitmq_cluster_create.yml diff --git a/tasks/main.yml b/tasks/main.yml index 3808ee36..ef5d556e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -66,6 +66,7 @@ - include: rabbitmq_cluster.yml tags: - rabbitmq_server-config + - rabbitmq-cluster - name: Flush handlers meta: flush_handlers diff --git a/tasks/rabbitmq_cluster.yml b/tasks/rabbitmq_cluster.yml index 4140496a..7e27594d 100644 --- a/tasks/rabbitmq_cluster.yml +++ b/tasks/rabbitmq_cluster.yml @@ -13,9 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -- include: rabbitmq_cluster_create.yml - static: no +- name: Get rabbitmq cluster name + shell: | + return_code=0 + if ! rabbitmqctl cluster_status | grep -w '<<"{{ rabbitmq_cluster_name }}">>'; then + rabbitmqctl set_cluster_name {{ rabbitmq_cluster_name }} + return_code=2 + fi + exit ${return_code} when: ansible_hostname == rabbitmq_primary_cluster_node + register: _set_cluster_name + changed_when: _set_cluster_name.rc == 2 + failed_when: _set_cluster_name.rc not in [0, 2] + # We skip ansible lint testing for this task as it fails with + # ANSIBLE0014 Environment variables don't work as part of command + # which is nonsense. + tags: + - skip_ansible_lint - include: rabbitmq_cluster_join.yml static: no diff --git a/tasks/rabbitmq_cluster_create.yml b/tasks/rabbitmq_cluster_create.yml deleted file mode 100644 index 4aaad5ad..00000000 --- a/tasks/rabbitmq_cluster_create.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -# Copyright 2014, Rackspace US, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -- block: - - name: Get rabbitmq cluster name - shell: | - rabbitmqctl cluster_status | grep -w '<<"{{ rabbitmq_cluster_name }}">>' - changed_when: false - tags: - - rabbitmq-cluster - - rescue: - - name: Create rabbitmq cluster - command: rabbitmqctl set_cluster_name {{ rabbitmq_cluster_name }} - tags: - - rabbitmq-cluster diff --git a/tasks/rabbitmq_cluster_join.yml b/tasks/rabbitmq_cluster_join.yml index a9b98c53..feb38bcd 100644 --- a/tasks/rabbitmq_cluster_join.yml +++ b/tasks/rabbitmq_cluster_join.yml @@ -21,15 +21,11 @@ shell: | rabbitmqctl -q cluster_status | grep '{cluster_name,<<"{{ rabbitmq_cluster_name }}">>}' changed_when: false - tags: - - rabbitmq-cluster rescue: - name: Stop rabbitmq app shell: | rabbitmqctl stop_app; sleep 5 - tags: - - rabbitmq-cluster - name: Join rabbitmq cluster command: > @@ -38,8 +34,6 @@ until: rabbit_join_cluster|success retries: 5 delay: 2 - tags: - - rabbitmq-cluster - name: Start rabbitmq app command: rabbitmqctl start_app @@ -47,5 +41,3 @@ until: rabbit_start_app|success retries: 5 delay: 2 - tags: - - rabbitmq-cluster