Skip to content

Commit

Permalink
Merge pull request #46 from gaima8/no-ha
Browse files Browse the repository at this point in the history
Separate the creation of exchange(s), queue(s), and binding(s) from HA policies
  • Loading branch information
mrlesmithjr authored Jul 9, 2021
2 parents fed388e + 7c4fdcb commit 84f6f90
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 41 deletions.
7 changes: 7 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ rabbitmq_config: []
# type: direct
# routing_key: logstash
# tags: "ha-mode=all,ha-sync-mode=automatic"
# - queue_name: logstash-quorum
# durable: true
# exchange_name: logstash-quorum
# type: direct
# routing_key: logstash
# queue_type: quorum
# tags: "ha-mode=all,ha-sync-mode=automatic"
# - policy_pattern: ".*"
# vhost: apps
# tags: "ha-mode=all,ha-sync-mode=automatic"
Expand Down
3 changes: 1 addition & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@
- include: rabbitmq_vhosts.yml
when: rabbitmq_extra_vhosts is defined

- include: rabbitmq_ha_config.yml
- include: rabbitmq_config.yml
when: >
rabbitmq_config_ha and
rabbitmq_enable_clustering and
rabbitmq_config is defined
Expand Down
42 changes: 42 additions & 0 deletions tasks/rabbitmq_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
- name: rabbitmq_config | checking if rabbitmqadmin is installed
stat:
path: /usr/sbin/rabbitmqadmin
register: rabbitmqadmin_check

- name: rabbit_config | Installing rabbitMQ admin
get_url:
url: http://guest:guest@localhost:15672/cli/rabbitmqadmin
dest: /usr/sbin/rabbitmqadmin
mode: u=rwx,g=rw,o=rw
become: true
notify: restart rabbitmq-server
when: not rabbitmqadmin_check['stat']['exists']

- name: rabbitmq_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_config | creating queue(s)
command: rabbitmqadmin declare queue name={{ item['queue_name'] }} durable={{ item['durable']|lower }} --vhost={{ item['vhost'] | default('/') }} queue_type={{ item['queue_type'] | default('classic') }}
run_once: true
delegate_to: "{{ rabbitmq_master }}"
become: true
when:
- item['queue_name'] is defined
with_items: "{{ rabbitmq_config }}"

- include: rabbitmq_ha_config.yml
when: rabbitmq_config_ha

- name: rabbitmq_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('/') }} # noqa 204
run_once: true
delegate_to: "{{ rabbitmq_master }}"
become: true
with_items: "{{ rabbitmq_config }}"
when: item['exchange_name'] is defined and item['queue_name'] is defined
39 changes: 0 additions & 39 deletions tasks/rabbitmq_ha_config.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
---
- name: rabbitmq_ha_config | checking if rabbitmqadmin is installed
stat:
path: /usr/sbin/rabbitmqadmin
register: rabbitmqadmin_check

- name: rabbit_ha_config | Installing rabbitMQ admin
get_url:
url: http://guest:guest@localhost:15672/cli/rabbitmqadmin
dest: /usr/sbin/rabbitmqadmin
mode: u=rwx,g=rw,o=rw
become: true
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
with_items: "{{ rabbitmq_config }}"

- name: rabbitmq_ha_config | setting up ha on queue(s)
rabbitmq_policy:
name: "ha-all{{ policy_name }}"
Expand All @@ -45,11 +14,3 @@
become: true
when: item.queue_name is defined or item.policy_pattern is defined
with_items: "{{ rabbitmq_config }}"

- 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('/') }} # noqa 204
run_once: true
delegate_to: "{{ rabbitmq_master }}"
become: true
with_items: "{{ rabbitmq_config }}"
when: item['exchange_name'] is defined

0 comments on commit 84f6f90

Please sign in to comment.