diff options
Diffstat (limited to 'tasks/rabbitmq_clustering.yml')
-rw-r--r-- | tasks/rabbitmq_clustering.yml | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/tasks/rabbitmq_clustering.yml b/tasks/rabbitmq_clustering.yml index 5134c50..9e48590 100644 --- a/tasks/rabbitmq_clustering.yml +++ b/tasks/rabbitmq_clustering.yml | |||
@@ -1,21 +1,30 @@ | |||
1 | --- | 1 | --- |
2 | - name: rabbitmq_clustering | stopping rabbitmq app | 2 | - name: rabbitmq_clustering | stopping rabbitmq app |
3 | command: rabbitmqctl stop_app | 3 | command: rabbitmqctl stop_app |
4 | when: inventory_hostname != "{{ rabbitmq_master }}" | 4 | become: true |
5 | when: inventory_hostname != rabbitmq_master | ||
5 | 6 | ||
6 | - name: rabbitmq_clustering | resetting rabbitmq app | 7 | - name: rabbitmq_clustering | resetting rabbitmq app |
7 | command: rabbitmqctl reset | 8 | command: rabbitmqctl reset |
8 | when: inventory_hostname != "{{ rabbitmq_master }}" | 9 | become: true |
10 | when: inventory_hostname != rabbitmq_master | ||
9 | 11 | ||
10 | - name: rabbitmq_clustering | stopping rabbitmq-server | 12 | - name: rabbitmq_clustering | stopping rabbitmq-server |
11 | service: | 13 | service: |
12 | name: rabbitmq-server | 14 | name: rabbitmq-server |
13 | state: stopped | 15 | state: stopped |
16 | become: true | ||
14 | 17 | ||
15 | #- name: grabbing erlang cookie | 18 | - name: rabbitmq_clustering | Capturing Erlang Cookie On Master |
16 | # shell: cat /var/lib/rabbitmq/.erlang.cookie | 19 | command: "cat {{ rabbitmq_erlang_cookie_file }}" |
17 | # register: rabbitmq_erlang_cookie | 20 | become: true |
18 | # when: inventory_hostname == "{{ rabbitmq_master }}" | 21 | register: "rabbitmq_erlang_cookie" |
22 | when: inventory_hostname == rabbitmq_master | ||
23 | |||
24 | - name: rabbitmq_clustering | Setting Erlang Cookie Of Master on Non-Master | ||
25 | set_fact: | ||
26 | rabbitmq_erlang_cookie: "{{ hostvars[rabbitmq_master]['rabbitmq_erlang_cookie']['stdout'] }}" | ||
27 | when: inventory_hostname != rabbitmq_master | ||
19 | 28 | ||
20 | - name: rabbitmq_clustering | copy erlang cookie | 29 | - name: rabbitmq_clustering | copy erlang cookie |
21 | template: | 30 | template: |
@@ -24,49 +33,62 @@ | |||
24 | owner: rabbitmq | 33 | owner: rabbitmq |
25 | group: rabbitmq | 34 | group: rabbitmq |
26 | mode: 0400 | 35 | mode: 0400 |
27 | backup: yes #backing up in case the need to recover | 36 | # backing up in case the need to recover |
28 | # when: inventory_hostname != "{{ rabbitmq_master }}" | 37 | backup: yes |
38 | become: true | ||
39 | when: inventory_hostname != rabbitmq_master | ||
29 | 40 | ||
30 | - name: rabbitmq_clustering | restarting rabbitmq-server on master | 41 | - name: rabbitmq_clustering | restarting rabbitmq-server on master |
31 | service: | 42 | service: |
32 | name: rabbitmq-server | 43 | name: rabbitmq-server |
33 | state: restarted | 44 | state: restarted |
34 | when: inventory_hostname == "{{ rabbitmq_master }}" | 45 | become: true |
46 | when: inventory_hostname == rabbitmq_master | ||
35 | 47 | ||
36 | - name: rabbitmq_clustering | starting rabbitmq app on master | 48 | - name: rabbitmq_clustering | starting rabbitmq app on master |
37 | command: rabbitmqctl start_app | 49 | command: rabbitmqctl start_app |
38 | register: cluster_master | 50 | register: cluster_master |
39 | when: inventory_hostname == "{{ rabbitmq_master }}" | 51 | become: true |
52 | when: inventory_hostname == rabbitmq_master | ||
40 | 53 | ||
41 | - name: rabbitmq_clustering | sending sigterm to any running rabbitmq processes | 54 | - name: rabbitmq_clustering | sending sigterm to any running rabbitmq processes |
42 | shell: pkill -u rabbitmq || true | 55 | shell: pkill -u rabbitmq || true |
43 | when: inventory_hostname != "{{ rabbitmq_master }}" | 56 | become: true |
57 | when: inventory_hostname != rabbitmq_master | ||
44 | 58 | ||
45 | - name: rabbitmq_clustering | restarting rabbitmq-server | 59 | - name: rabbitmq_clustering | restarting rabbitmq-server |
46 | service: | 60 | service: |
47 | name: rabbitmq-server | 61 | name: rabbitmq-server |
48 | state: restarted | 62 | state: restarted |
49 | when: inventory_hostname != "{{ rabbitmq_master }}" | 63 | become: true |
64 | when: inventory_hostname != rabbitmq_master | ||
50 | 65 | ||
51 | - name: rabbitmq_clustering | stopping rabbitmq app | 66 | - name: rabbitmq_clustering | stopping rabbitmq app |
52 | command: rabbitmqctl stop_app | 67 | command: rabbitmqctl stop_app |
53 | when: inventory_hostname != "{{ rabbitmq_master }}" | 68 | become: true |
69 | when: inventory_hostname != rabbitmq_master | ||
54 | 70 | ||
55 | - name: rabbitmq_clustering | resetting rabbitmq app | 71 | - name: rabbitmq_clustering | resetting rabbitmq app |
56 | command: rabbitmqctl reset | 72 | command: rabbitmqctl reset |
57 | when: inventory_hostname != "{{ rabbitmq_master }}" | 73 | become: true |
74 | when: inventory_hostname != rabbitmq_master | ||
58 | 75 | ||
59 | - name: rabbitmq_clustering | joining rabbitmq cluster | 76 | - name: rabbitmq_clustering | joining rabbitmq cluster |
60 | command: rabbitmqctl join_cluster "rabbit@{{ hostvars[rabbitmq_master]['ansible_hostname'] }}" | 77 | command: rabbitmqctl join_cluster "rabbit@{{ hostvars[rabbitmq_master]['ansible_hostname'] }}" |
61 | register: cluster_joined | 78 | register: cluster_joined |
62 | when: inventory_hostname != "{{ rabbitmq_master }}" | 79 | become: true |
80 | when: inventory_hostname != rabbitmq_master | ||
63 | 81 | ||
64 | - name: rabbitmq_clustering | starting rabbitmq app | 82 | - name: rabbitmq_clustering | starting rabbitmq app |
65 | command: rabbitmqctl start_app | 83 | command: rabbitmqctl start_app |
66 | when: inventory_hostname != "{{ rabbitmq_master }}" | 84 | become: true |
85 | when: inventory_hostname != rabbitmq_master | ||
67 | 86 | ||
68 | - name: rabbitmq_clustering | marking as clustered | 87 | - name: rabbitmq_clustering | marking as clustered |
69 | file: | 88 | file: |
70 | path: /etc/rabbitmq/clustered | 89 | path: /etc/rabbitmq/clustered |
71 | state: touch | 90 | state: touch |
72 | when: cluster_master.changed or cluster_joined.changed | 91 | become: true |
92 | when: > | ||
93 | cluster_master['changed'] or | ||
94 | cluster_joined['changed'] | ||