aboutsummaryrefslogtreecommitdiffhomepage
path: root/tasks/rabbitmq_vhosts.yml
blob: a02af62b3500e37dad7096d0eb523dffc24b2d83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---
- name: rabbitmq_extra_vhosts | Create vhosts
  rabbitmq_vhost:
    name: "{{ item['name'] }}"
    state: "{{ item['state'] }}"
  with_items: "{{ rabbitmq_extra_vhosts }}"
  run_once: "{{ rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering }}"
  register: rabbitmq_created_vhosts

- name: rabbitmq_extra_vhosts | Check guest administrator is present
  command: rabbitmqctl -q list_users
  become: true
  run_once: "{{ rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering }}"
  when: rabbitmq_created_vhosts.changed
  changed_when: false
  register: rabbitmq_existing_users

- name: rabbitmq_extra_vhosts | Give access to new vhosts to guest administrator
  command: "rabbitmqctl -q set_permissions -p {{ item['name'] }} guest '.*' '.*' '.*'"
  become: true
  run_once: "{{ rabbitmq_enable_clustering is defined and rabbitmq_enable_clustering }}"
  with_items: "{{ rabbitmq_created_vhosts.results|selectattr('changed')|list }}"
  when:
    - item['state'] == 'present'
    - rabbitmq_existing_users.stdout_lines | map('regex_search', '^guest\\s\\[.*administrator.*\\]$') | list | difference([None]) | length > 0