From c3b85a38ba6ce9465ee67c571916c5be11f683f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Duchaussois?= Date: Tue, 18 Dec 2018 11:36:00 +0100 Subject: Allow multiple policies creation --- defaults/main.yml | 3 +++ tasks/rabbitmq_ha_config.yml | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 9e9f3c8..41161c8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,9 @@ rabbitmq_config: [] # type: 'direct' # routing_key: 'logstash' # tags: 'ha-mode=all,ha-sync-mode=automatic' + # - policy_pattern: '.*' + # vhost: 'apps' + # tags: 'ha-mode=all,ha-sync-mode=automatic' # Defines if rabbitmq ha should be configured rabbitmq_config_ha: false diff --git a/tasks/rabbitmq_ha_config.yml b/tasks/rabbitmq_ha_config.yml index bf74957..e62fc83 100644 --- a/tasks/rabbitmq_ha_config.yml +++ b/tasks/rabbitmq_ha_config.yml @@ -24,16 +24,23 @@ command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} run_once: true become: true + when: + - item['queue_name'] is defined with_items: "{{ rabbitmq_config }}" - name: rabbitmq_ha_config | setting up ha on queue(s) rabbitmq_policy: - name: "ha-all" - pattern: "{{ item['queue_name'] }}" - tags: "{{ item['tags'] }}" + name: "ha-all{{ policy_name }}" + pattern: "{{ item.queue_name | default(item.policy_pattern) }}" + vhost: "{{ item.vhost | default('/') }}" + tags: "{{ item.tags }}" state: present + vars: + 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 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) -- cgit v1.2.3