diff --git a/tasks/rabbitmq/users.yml b/tasks/rabbitmq/users.yml index da1a2bf..e8a24cb 100644 --- a/tasks/rabbitmq/users.yml +++ b/tasks/rabbitmq/users.yml @@ -1,61 +1,34 @@ --- -rabbitmq_users: - - user: guest +- name: Remove users from rabbitmq + community.rabbitmq.rabbitmq_user: + user: "{{ item.user }}" state: absent - - user: rockyadmin - state: present - tags: "administrator" - permissions: - - vhost: / - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - - vhost: pubsub - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - - vhost: public_pubsub - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - - vhost: mbs - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - - vhost: distrobuild - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - - vhost: odcs - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - - user: mbs - state: present - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - vhost: mbs - - user: distrobuild - state: present - configure_priv: ".*" - read_priv: ".*" - write_priv: ".*" - vhost: distrobuild - - user: rockymonitor - state: present - permissions: - - vhost: / - configure_priv: "^$" - read_priv: "^$" - write_priv: "^$" - - vhost: pubsub - configure_priv: "^$" - read_priv: "^$" - write_priv: "^$" - - vhost: public_pubsub - configure_priv: "^$" - read_priv: "^$" - write_priv: "^$" - tags: "monitoring" + when: item.state == 'absent' + +- name: Add and configure single vhost users + community.rabbitmq.rabbitmq_user: + user: "{{ item.user }}" + password: "{{ item.password | default(omit) }}" + update_password: "{{ item.update_password | default(omit) }}" + topic_permissions: "{{ item.topic_permissions | default(omit) }}" + configure_priv: "{{ item.configure_priv | default(omit) }}" + write_priv: "{{ item.write_priv | default(omit) }}" + read_priv: "{{ item.read_priv | default(omit) }}" + vhost: "{{ item.vhost }}" + tags: "{{ item.tags | default(omit) }}" + loop: "{{ rabbitmq_users }}" + when: item.vhost is defined + +- name: Add and configure multi vhost users + community.rabbitmq.rabbitmq_user: + user: "{{ item.user }}" + password: "{{ item.password | default(omit) }}" + update_password: "{{ item.update_password | default(omit) }}" + topic_permissions: "{{ item.topic_permissions | default(omit) }}" + permissions: "{{ item.permissions }}" + tags: "{{ item.tags | default(omit) }}" + loop: "{{ rabbitmq_users }}" + when: + - item.vhost is not defined + - item.permissions is defined ... diff --git a/vars/rabbitmq_users.yml b/vars/rabbitmq_users.yml index 3067675..da1a2bf 100644 --- a/vars/rabbitmq_users.yml +++ b/vars/rabbitmq_users.yml @@ -1,35 +1,61 @@ --- -- name: Remove users from rabbitmq - community.rabbitmq.rabbitmq_user: - user: "{{ item.user }}" +rabbitmq_users: + - user: guest state: absent - when: item.state == 'absent' - -- name: Add and configure single vhost users - community.rabbitmq.rabbitmq_user: - user: "{{ item.user }}" - password: "{{ item.password|default(omit) }}" - update_password: "{{ item.update_password|default(omit) }}" - topic_permissions: "{{ item.topic_permissions|default(omit) }}" - configure_priv: "{{ item.configure_priv|default(omit) }}" - write_priv: "{{ item.write_priv|default(omit) }}" - read_priv: "{{ item.read_priv|default(omit) }}" - vhost: "{{ item.vhost }}" - tags: "{{ item.tags|default(omit) }}" - loop: "{{ rabbitmq_users }}" - when: item.vhost is defined - -- name: Add and configure multi-vhost users - community.rabbitmq.rabbitmq_user: - user: "{{ item.user }}" - password: "{{ item.password|default(omit) }}" - update_password: "{{ item.update_password|default(omit) }}" - permissions: "{{ item.permissions }}" - topic_permissions: "{{ item.topic_permissions|default(omit) }}" - vhost: "{{ item.vhost }}" - tags: "{{ item.tags|default(omit) }}" - loop: "{{ rabbitmq_users }}" - when: - - item.vhost is not defined - - item.permissions is defined + - user: rockyadmin + state: present + tags: "administrator" + permissions: + - vhost: / + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + - vhost: pubsub + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + - vhost: public_pubsub + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + - vhost: mbs + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + - vhost: distrobuild + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + - vhost: odcs + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + - user: mbs + state: present + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + vhost: mbs + - user: distrobuild + state: present + configure_priv: ".*" + read_priv: ".*" + write_priv: ".*" + vhost: distrobuild + - user: rockymonitor + state: present + permissions: + - vhost: / + configure_priv: "^$" + read_priv: "^$" + write_priv: "^$" + - vhost: pubsub + configure_priv: "^$" + read_priv: "^$" + write_priv: "^$" + - vhost: public_pubsub + configure_priv: "^$" + read_priv: "^$" + write_priv: "^$" + tags: "monitoring" ...