diff options
author | Paul Bonaud <paul.bonaud@fretlink.com> | 2018-12-20 11:03:39 +0100 |
---|---|---|
committer | Paul Bonaud <paul.bonaud@fretlink.com> | 2018-12-20 11:25:37 +0100 |
commit | fa6c482bae5ea36e52b575281feeab2649a8321f (patch) | |
tree | 9989385300c3a01eaae39ffcae38752cbab69230 | |
parent | d58696271f166b50faa2705fdda6337c1ffb493c (diff) | |
download | ansible-rabbitmq-fa6c482bae5ea36e52b575281feeab2649a8321f.tar.gz ansible-rabbitmq-fa6c482bae5ea36e52b575281feeab2649a8321f.tar.zst ansible-rabbitmq-fa6c482bae5ea36e52b575281feeab2649a8321f.zip |
clustering: make sure to delegate admin tasks to the master node
-rw-r--r-- | defaults/main.yml | 5 | ||||
-rw-r--r-- | tasks/rabbitmq_ha_config.yml | 18 | ||||
-rw-r--r-- | tasks/rabbitmq_users.yml | 1 |
3 files changed, 14 insertions, 10 deletions
diff --git a/defaults/main.yml b/defaults/main.yml index f3d2c20..4ea3ee0 100644 --- a/defaults/main.yml +++ b/defaults/main.yml | |||
@@ -29,6 +29,8 @@ rabbitmq_debian_version: 3.7.9 | |||
29 | 29 | ||
30 | # Defines if setting up a rabbitmq cluster | 30 | # Defines if setting up a rabbitmq cluster |
31 | rabbitmq_enable_clustering: false | 31 | rabbitmq_enable_clustering: false |
32 | # Defines the inventory host that should be considered master | ||
33 | rabbitmq_master: None | ||
32 | 34 | ||
33 | rabbitmq_erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie | 35 | rabbitmq_erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie |
34 | 36 | ||
@@ -50,9 +52,6 @@ rabitmq_ssl_options: {} | |||
50 | # verify: verify_peer | 52 | # verify: verify_peer |
51 | # fail_if_no_peer_cert: "false" | 53 | # fail_if_no_peer_cert: "false" |
52 | 54 | ||
53 | # Defines the inventory host that should be considered master | ||
54 | rabbitmq_master: [] | ||
55 | |||
56 | rabbitmq_redhat_repo_key: https://www.rabbitmq.com/rabbitmq-signing-key-public.asc | 55 | rabbitmq_redhat_repo_key: https://www.rabbitmq.com/rabbitmq-signing-key-public.asc |
57 | rabbitmq_redhat_package: "rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm" | 56 | rabbitmq_redhat_package: "rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm" |
58 | rabbitmq_redhat_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}" | 57 | rabbitmq_redhat_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}" |
diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml index cea301c..322172d 100644 --- a/tasks/rabbitmq_ha_config.yml +++ b/tasks/rabbitmq_ha_config.yml | |||
@@ -13,9 +13,18 @@ | |||
13 | notify: restart rabbitmq-server | 13 | notify: restart rabbitmq-server |
14 | when: not rabbitmqadmin_check['stat']['exists'] | 14 | when: not rabbitmqadmin_check['stat']['exists'] |
15 | 15 | ||
16 | - name: rabbitmq_ha_config | creating exchange(s) | ||
17 | command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} --vhost={{ item['vhost'] | default('/') }} | ||
18 | run_once: true | ||
19 | delegate_to: "{{ rabbitmq_master }}" | ||
20 | become: true | ||
21 | with_items: "{{ rabbitmq_config }}" | ||
22 | when: item['exchange_name'] is defined | ||
23 | |||
16 | - name: rabbitmq_ha_config | creating queue(s) | 24 | - name: rabbitmq_ha_config | creating queue(s) |
17 | command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} --vhost={{ item['vhost'] | default('/') }} | 25 | command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} --vhost={{ item['vhost'] | default('/') }} |
18 | run_once: true | 26 | run_once: true |
27 | delegate_to: "{{ rabbitmq_master }}" | ||
19 | become: true | 28 | become: true |
20 | when: | 29 | when: |
21 | - item['queue_name'] is defined | 30 | - item['queue_name'] is defined |
@@ -32,20 +41,15 @@ | |||
32 | policy_vhost: "{{ item.vhost | default('/') }}" | 41 | policy_vhost: "{{ item.vhost | default('/') }}" |
33 | policy_name: "{{ item.policy_pattern is defined | ternary(policy_vhost + item.policy_pattern|default(''),item.queue_name|default('')) }}" | 42 | policy_name: "{{ item.policy_pattern is defined | ternary(policy_vhost + item.policy_pattern|default(''),item.queue_name|default('')) }}" |
34 | run_once: true | 43 | run_once: true |
44 | delegate_to: "{{ rabbitmq_master }}" | ||
35 | become: true | 45 | become: true |
36 | when: item.queue_name is defined or item.policy_pattern is defined | 46 | when: item.queue_name is defined or item.policy_pattern is defined |
37 | with_items: "{{ rabbitmq_config }}" | 47 | with_items: "{{ rabbitmq_config }}" |
38 | 48 | ||
39 | - name: rabbitmq_ha_config | creating exchange(s) | ||
40 | command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} --vhost={{ item['vhost'] | default('/') }} | ||
41 | run_once: true | ||
42 | become: true | ||
43 | with_items: "{{ rabbitmq_config }}" | ||
44 | when: item['exchange_name'] is defined | ||
45 | |||
46 | - name: rabbitmq_ha_config | creating binding(s) | 49 | - name: rabbitmq_ha_config | creating binding(s) |
47 | command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} --vhost={{ item['vhost'] | default('/') }} | 50 | command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} --vhost={{ item['vhost'] | default('/') }} |
48 | run_once: true | 51 | run_once: true |
52 | delegate_to: "{{ rabbitmq_master }}" | ||
49 | become: true | 53 | become: true |
50 | with_items: "{{ rabbitmq_config }}" | 54 | with_items: "{{ rabbitmq_config }}" |
51 | when: item['exchange_name'] is defined | 55 | when: item['exchange_name'] is defined |
diff --git a/tasks/rabbitmq_users.yml b/tasks/rabbitmq_users.yml index 98e45e2..083c704 100644 --- a/tasks/rabbitmq_users.yml +++ b/tasks/rabbitmq_users.yml | |||
@@ -27,6 +27,7 @@ | |||
27 | tags: "{{ item['tags'] }}" | 27 | tags: "{{ item['tags'] }}" |
28 | state: present | 28 | state: present |
29 | run_once: yes | 29 | run_once: yes |
30 | delegate_to: "{{ rabbitmq_master }}" | ||
30 | become: true | 31 | become: true |
31 | with_items: "{{ rabbitmq_users }}" | 32 | with_items: "{{ rabbitmq_users }}" |
32 | when: > | 33 | when: > |