# Using rabbitmq\_user module with multiple permissions

**URL:** <https://forum.ansible.com/t/using-rabbitmq-user-module-with-multiple-permissions/23459>\
**Category:** Ansible Developer\
**Created:** [January 14, 2017, 11:11am UTC](https://forum.ansible.com/t/using-rabbitmq-user-module-with-multiple-permissions/23459 "2017-01-14T11:11:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan82](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@Dan82](https://forum.ansible.com/u/Dan82)\
**Post date:** [January 14, 2017, 11:11am UTC](https://forum.ansible.com/t/using-rabbitmq-user-module-with-multiple-permissions/23459/1 "2017-01-14T11:11:28Z")

</div>

Hello,

I’m working on a rabbitmqAnsible role and I have to write the task dedicated to users creation and configuration.

I defined the following variable in my playbook:  
vars:

- rabbitmq\_resources:
- type\_resource: “vhost”  
name: “/test”  
node: “rabbit@host1ansible”
- type\_resource: “vhost”  
name: “/other”  
node: “rabbit@host1ansible”
- type\_resource: “user”  
name: “rabbitmqadmin”  
password: “rabbitmqadmin”  
permissions:
- vhost: “/test”  
configure\_priv: “._"  
read\_priv: "._”  
write\_priv: “.\*”
- vhost: “/other”  
configure\_priv: “._"  
read\_priv: "._”  
write\_priv: “.\*”  
tags: “administrator”  
state: present

Then I want to write the task code dedicated to user processing:

- name: Creating RabbitMQ users  
rabbitmq\_user:  
name: “{{ item.name|mandatory }}”  
permissions:  
vhost: “{{ item.value.vhost }}”  
configure\_priv: “{{ item.value.configure\_priv }}”  
read\_priv: “{{ item.value.read\_priv }}”  
write\_priv: “{{ item.value.write\_priv }}”  
tags: “{{ item.tags }}”  
state: present  
with\_subelements:
- “{{ rabbitmq\_resources }}”
- type\_resource
- permissions  
when: item.type\_resource == “user”

The syntax above generates a message “subelements lookup expects a list of two or three items, the optional third item must be a dict with flags skip\_missing”.  
I tested various loop syntaxes (with\_items, with\_subelements, with\_dict) but I’m still unable to find the right one.

Help will be appreciated.

Thank’s  
Dan

---

<div class="post-metadata">

**Author:** ![Dan82](https://avatars.discourse-cdn.com/v4/letter/d/ea5d25/32.png) [@Dan82](https://forum.ansible.com/u/Dan82)\
**Post date:** [January 14, 2017, 5:31pm UTC](https://forum.ansible.com/t/using-rabbitmq-user-module-with-multiple-permissions/23459/2 "2017-01-14T17:31:54Z")

</div>

Finally, I decided to replace the permissions list by a JSON array:  
permissions: [{“vhost”: “/test”,“configure\_priv”: “._",“read\_priv”: "._”,“write\_priv”: “._"},  
{“vhost”: “/other”,“configure\_priv”: "._”,“read\_priv”: “._",“write\_priv”: "._”}]

The task code is now:

- name: Creating RabbitMQ users  
rabbitmq\_user:  
name: “{{ item.name|mandatory }}”  
permissions: “{{ item.permissions }}”  
tags: “{{ item.tags }}”  
state: present  
with\_items: “{{ rabbitmq\_resources }}”  
when: item.type\_resource == “user”

and it works fine.

Dan
