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
This commit is contained in:
parent
df2e973bee
commit
3b897ad515
@ -66,6 +66,7 @@
|
||||
- include: rabbitmq_cluster.yml
|
||||
tags:
|
||||
- rabbitmq_server-config
|
||||
- rabbitmq-cluster
|
||||
|
||||
- name: Flush handlers
|
||||
meta: flush_handlers
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user