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