From 84d38251e016aebeb6fc72a5c76a486f0542212b Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Mon, 17 Dec 2018 19:02:27 +0100 Subject: vhosts: Adding rabbitmq vhosts creation --- defaults/main.yml | 5 +++++ tasks/main.yml | 3 +++ tasks/rabbitmq_vhosts.yml | 7 +++++++ 3 files changed, 15 insertions(+) create mode 100644 tasks/rabbitmq_vhosts.yml diff --git a/defaults/main.yml b/defaults/main.yml index f3d2c20..f7138a7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -58,6 +58,11 @@ rabbitmq_redhat_package: "rabbitmq-server-{{ rabbitmq_redhat_version }}-1.noarch rabbitmq_redhat_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v{{ rabbitmq_redhat_version }}" rabbitmq_redhat_version: 3.6.1 +# Define extra vhosts to be created +rabbitmq_extra_vhosts: [] +# - name: / +# state: present + # Define admin user to create in order to login to WebUI rabbitmq_users: - name: rabbitmqadmin diff --git a/tasks/main.yml b/tasks/main.yml index 1ef08f0..a9dc4d2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -26,6 +26,9 @@ rabbitmq_enable_clustering and not clustered['stat']['exists'] +- include: rabbitmq_vhosts.yml + when: rabbitmq_extra_vhosts is defined + - include: rabbitmq_ha_config.yml when: > rabbitmq_config_ha and diff --git a/tasks/rabbitmq_vhosts.yml b/tasks/rabbitmq_vhosts.yml new file mode 100644 index 0000000..790ac18 --- /dev/null +++ b/tasks/rabbitmq_vhosts.yml @@ -0,0 +1,7 @@ +--- +- name: 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 }}" -- cgit v1.2.3 From 18be22a714897afa9da5db7e59bc02f606d6d6d7 Mon Sep 17 00:00:00 2001 From: Paul Bonaud Date: Thu, 20 Dec 2018 18:25:54 +0100 Subject: vhosts: give full permissions to default guest administrator --- tasks/rabbitmq_vhosts.yml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tasks/rabbitmq_vhosts.yml b/tasks/rabbitmq_vhosts.yml index 790ac18..a02af62 100644 --- a/tasks/rabbitmq_vhosts.yml +++ b/tasks/rabbitmq_vhosts.yml @@ -1,7 +1,25 @@ --- -- name: Create vhosts +- 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 -- cgit v1.2.3