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 ...