From ff5cb35875b9e6d8d5c2936697d3fa62c7a471b4 Mon Sep 17 00:00:00 2001 From: Louis Abel Date: Sat, 22 Jul 2023 21:25:14 -0700 Subject: [PATCH] add rabbitmq topics --- tasks/rabbitmq/topics.yml | 32 ++++++++++++++++++++++++++++++++ tasks/rabbitmq/users.yml | 1 + vars/rabbitmq.yml | 1 + vars/rabbitmq_topics.yml | 11 ++++++++++- 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tasks/rabbitmq/topics.yml diff --git a/tasks/rabbitmq/topics.yml b/tasks/rabbitmq/topics.yml new file mode 100644 index 0000000..5d51313 --- /dev/null +++ b/tasks/rabbitmq/topics.yml @@ -0,0 +1,32 @@ +--- +- name: Add topic exchanges + run_once: true + delegate_to: "{{ rabbitmq_cluster_list[0] }}" + community.rabbitmq.rabbitmq_exchange: + name: "{{ item.0.name }}" + exchange_type: "{{ item.0.exchange_type }}" + vhost: "{{ item.1.vhost }}" + login_user: "{{ rabbitmq_admin }}" + login_password: "{{ rabbitmq_admin_password }}" + loop: "{{ rabbitmq_topics | subelements('vhosts', 'skip_missing=True') }}" + when: rabbitmq_admin_password is defined + tags: + - rabbitmq_cluster + +- name: Forward topics if configured + run_once: true + delegate_to: "{{ rabbitmq_cluster_list[0] }}" + community.rabbitmq.rabbitmq_binding: + destination_type: "{{ item.1.destination_type }}" + name: "{{ item.0.name }}" + dest: "{{ item.1.destination}}" + routing_key: "{{ item.1.routing_key }}" + vhost: "{{ item.1.vhost }}" + login_user: "{{ rabbitmq_admin }}" + login_password: "{{ rabbitmq_admin_password }}" + when: + - rabbitmq_admin_password is defined + - item.1.binding|bool + tags: + - rabbitmq_cluster +... diff --git a/tasks/rabbitmq/users.yml b/tasks/rabbitmq/users.yml index 9b7965d..b35f9d9 100644 --- a/tasks/rabbitmq/users.yml +++ b/tasks/rabbitmq/users.yml @@ -3,6 +3,7 @@ community.rabbitmq.rabbitmq_user: user: "{{ item.user }}" state: absent + loop: "{{ rabbitmq_users }}" when: item.state == 'absent' - name: Add and configure single vhost users diff --git a/vars/rabbitmq.yml b/vars/rabbitmq.yml index 6c167c2..597fd20 100644 --- a/vars/rabbitmq.yml +++ b/vars/rabbitmq.yml @@ -9,6 +9,7 @@ rabbitmq_tls_key: "/etc/pki/tls/private/{{ ansible_fqdn }}.key" # rabbitmq_cookie: ... # Admin passwords - these should be in a vault +rabbitmq_admin: "rockyadmin" # rabbitmq_admin_password: ... # rabbitmq cluster list and information should be defined in hostvars to ensure diff --git a/vars/rabbitmq_topics.yml b/vars/rabbitmq_topics.yml index 38104f0..b4dc753 100644 --- a/vars/rabbitmq_topics.yml +++ b/vars/rabbitmq_topics.yml @@ -1,4 +1,13 @@ --- rabbitmq_topics: - - + - name: "zmq.topic" + exchange_type: "topic" + vhosts: + - vhost: "public_pubsub" + destination: "amq.topic" + destination_type: "exchange" + routing_key: "#" + binding: true + - vhost: "pubsub" + binding: false ...