From fa6c482bae5ea36e52b575281feeab2649a8321f Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Thu, 20 Dec 2018 11:03:39 +0100 Subject: [PATCH] clustering: make sure to delegate admin tasks to the master node --- defaults/main.yml | 5 ++--- tasks/rabbitmq_ha_config.yml | 18 +++++++++++------- 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 # Defines if setting up a rabbitmq cluster rabbitmq_enable_clustering: false +# Defines the inventory host that should be considered master +rabbitmq_master: None rabbitmq_erlang_cookie_file: /var/lib/rabbitmq/.erlang.cookie @@ -50,9 +52,6 @@ rabitmq_ssl_options: {} # verify: verify_peer # fail_if_no_peer_cert: "false" -# Defines the inventory host that should be considered master -rabbitmq_master: [] - rabbitmq_redhat_repo_key: https://www.rabbitmq.com/rabbitmq-signing-key-public.asc rabbitmq_redhat_package: "rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch.rpm" 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 @@ notify: restart rabbitmq-server when: not rabbitmqadmin_check['stat']['exists'] +- name: rabbitmq_ha_config | creating exchange(s) + command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} --vhost={{ item['vhost'] | default('/') }} + run_once: true + delegate_to: "{{ rabbitmq_master }}" + become: true + with_items: "{{ rabbitmq_config }}" + when: item['exchange_name'] is defined + - name: rabbitmq_ha_config | creating queue(s) command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} --vhost={{ item['vhost'] | default('/') }} run_once: true + delegate_to: "{{ rabbitmq_master }}" become: true when: - item['queue_name'] is defined @@ -32,20 +41,15 @@ policy_vhost: "{{ item.vhost | default('/') }}" policy_name: "{{ item.policy_pattern is defined | ternary(policy_vhost + item.policy_pattern|default(''),item.queue_name|default('')) }}" run_once: true + delegate_to: "{{ rabbitmq_master }}" become: true when: item.queue_name is defined or item.policy_pattern is defined with_items: "{{ rabbitmq_config }}" -- name: rabbitmq_ha_config | creating exchange(s) - command: rabbitmqadmin declare exchange name={{ item['exchange_name'] }} type={{ item['type'] }} --vhost={{ item['vhost'] | default('/') }} - run_once: true - become: true - with_items: "{{ rabbitmq_config }}" - when: item['exchange_name'] is defined - - name: rabbitmq_ha_config | creating binding(s) command: rabbitmqadmin declare binding source={{ item['exchange_name'] }} destination_type="queue" destination={{ item['queue_name'] }} routing_key={{ item['routing_key'] }} --vhost={{ item['vhost'] | default('/') }} run_once: true + delegate_to: "{{ rabbitmq_master }}" become: true with_items: "{{ rabbitmq_config }}" 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 @@ tags: "{{ item['tags'] }}" state: present run_once: yes + delegate_to: "{{ rabbitmq_master }}" become: true with_items: "{{ rabbitmq_users }}" when: > -- 2.41.0