summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/ansible/roles/mq/tasks/rabbitmq_cluster.yml
blob: b67df28057c38c4ce212775c6e8a669258a6f55d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
##############################################################################
# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# 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 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