I’m using the following simple task in Ansible to create a rabbitmq exchange:
- hosts: rabbitmq
tasks:
- name: Add my exchange
debugger: on_failed
community.rabbitmq.rabbitmq_exchange:
login_user: "{{ rabbitmq_admin_user }}"
login_password: "{{ rabbitmq_admin_password }}"
vhost: "{{ rabbitmq_vhost }}"
name: "{{ rabbitmq_exchange_name }}"
durable: true
exchange_type: direct
state: present
The task fails with the following error and Ansible enters into debug mode, which I can see the correct password and username is provided:
FAILED! => {“changed”: false, “details”: “{“error”:”not_authorised”,”reason”:”Access refused.”}”, “msg”: “Error creating exchange”, “status”: 401}
TASK: Add my exchange (debug)>p task.args
...
...
login_password: mypassword
login_user: admin
...
When I ssh into the host ansible is managing and execute a curl command to access rabbitmq management REST API like this, it works and gives me the list of vhosts:
curl -i -u admin:'mypassword' http://localhost:15672/api/vhosts
My rabbitmq version is 3.12.1 and my ansible module version is 1.3.0.
What can be the cause of the problem? Note that mypassword actually contains many different non-alphanumeric characters so I pass it like ‘mypassword’ to the curl command.