Skip to content

fix: RabbitMQ user module API response success conditions to include 201 and 204#219

Open
vajeen wants to merge 1 commit intoansible-collections:mainfrom
vajeen:rabbirmq_user_accept_2xx_as_success
Open

fix: RabbitMQ user module API response success conditions to include 201 and 204#219
vajeen wants to merge 1 commit intoansible-collections:mainfrom
vajeen:rabbirmq_user_accept_2xx_as_success

Conversation

@vajeen
Copy link

@vajeen vajeen commented Feb 21, 2026

SUMMARY

Fixes #217 where incorrect handling of successful HTTP 204 (No Content) responses in the rabbitmq_user module when interacting with the RabbitMQ HTTP API.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

rabbitmq_user

ADDITIONAL INFORMATION

Test playbook

---
- name: Test rabbitmq_user module
  hosts: localhost
  gather_facts: false
  
  vars:
    rmq_host: "localhost"
    rmq_port: "15672"
    rmq_protocol: "http"
    rabbitmq_admin_user: "guest"
    rabbitmq_admin_password: "guest"
    
    test_user: "test_user"
    test_password: "initial_password"
    new_password: "updated_password"
    test_vhost: "/"

  tasks:
    - name: 1. Create the user for the first time
      community.rabbitmq.rabbitmq_user:
        user: "{{ test_user }}"
        password: "{{ test_password }}"
        tags: "management"
        vhost: "{{ test_vhost }}"
        configure_priv: ".*"
        write_priv: ".*"
        read_priv: ".*"
        state: present
        update_password: always
        login_host: "{{ rmq_host }}"
        login_port: "{{ rmq_port }}"
        login_protocol: "{{ rmq_protocol }}"
        login_user: "{{ rabbitmq_admin_user }}"
        login_password: "{{ rabbitmq_admin_password }}"

    - name: 2. Run the exact same task again
      community.rabbitmq.rabbitmq_user:
        user: "{{ test_user }}"
        password: "{{ test_password }}"
        tags: "management"
        vhost: "{{ test_vhost }}"
        configure_priv: ".*"
        write_priv: ".*"
        read_priv: ".*"
        state: present
        update_password: always
        login_host: "{{ rmq_host }}"
        login_port: "{{ rmq_port }}"
        login_protocol: "{{ rmq_protocol }}"
        login_user: "{{ rabbitmq_admin_user }}"
        login_password: "{{ rabbitmq_admin_password }}"

    - name: 3. Update the user's password (this triggered the 204 error previously)
      community.rabbitmq.rabbitmq_user:
        user: "{{ test_user }}"
        password: "{{ new_password }}"
        tags: "management"
        vhost: "{{ test_vhost }}"
        configure_priv: ".*"
        write_priv: ".*"
        read_priv: ".*"
        state: present
        update_password: always
        login_host: "{{ rmq_host }}"
        login_port: "{{ rmq_port }}"
        login_protocol: "{{ rmq_protocol }}"
        login_user: "{{ rabbitmq_admin_user }}"
        login_password: "{{ rabbitmq_admin_password }}"

    - name: 4. Update the user's tags (this triggered the 204 error previously)
      community.rabbitmq.rabbitmq_user:
        user: "{{ test_user }}"
        password: "{{ new_password }}"
        tags: "monitoring, management"
        vhost: "{{ test_vhost }}"
        configure_priv: ".*"
        write_priv: ".*"
        read_priv: ".*"
        state: present
        update_password: always
        login_host: "{{ rmq_host }}"
        login_port: "{{ rmq_port }}"
        login_protocol: "{{ rmq_protocol }}"
        login_user: "{{ rabbitmq_admin_user }}"
        login_password: "{{ rabbitmq_admin_password }}"

    - name: 5. Clean up - Remove the test user
      community.rabbitmq.rabbitmq_user:
        user: "{{ test_user }}"
        state: absent
        login_host: "{{ rmq_host }}"
        login_port: "{{ rmq_port }}"
        login_protocol: "{{ rmq_protocol }}"
        login_user: "{{ rabbitmq_admin_user }}"
        login_password: "{{ rabbitmq_admin_password }}"

Output Before

ansible-playbook  rmq-test.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Test rabbitmq_user module] *******************************************************************************************************************************

TASK [1. Create the user for the first time] **********************************************************************************************************************************
changed: [localhost]

TASK [2. Run the exact same task again ****************************************************************************************
ok: [localhost]

TASK [3. Update the user's password (this triggered the 204 error previously)] ************************************************************************************************
[ERROR]: Task failed: Module failed: Error trying to set tags for the user test_ai_user in rabbitmq. Status code '204'.
Origin: /Users/mac/Development/Oneflow/oneflow-iac-test/rmq-test.yml:54:7

52         login_password: "{{ rabbitmq_admin_password }}"
53
54     - name: 3. Update the user's password (this triggered the 204 error previously)
         ^ column 7

fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error trying to set tags for the user test_ai_user in rabbitmq. Status code '204'."}

PLAY RECAP ********************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

Output After

ansible-playbook  rmq-test.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Test rabbitmq_user module] *******************************************************************************************************************************

TASK [1. Create the user for the first time] **********************************************************************************************************************************
changed: [localhost]

TASK [2. Run the exact same task again ****************************************************************************************
ok: [localhost]

TASK [3. Update the user's password (this triggered the 204 error previously)] ************************************************************************************************
changed: [localhost]

TASK [4. Update the user's tags (this triggered the 204 error previously)] ****************************************************************************************************
changed: [localhost]

TASK [5. Clean up - Remove the test user] *************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ********************************************************************************************************************************************************************
localhost                  : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

…04, and use `treat_tags_for_api` for user tag updates.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug when updating user password

1 participant