This PR is a refactoring of the RabbitMQ User module so that in the beginning of every operation it checks the version of the daemon and then, whenever possible, adds flags to the rabbitmqctl so that the output is a JSON document which can then be parsed in an easier and less "hacky" way. It is a more permanent solution relative to this PR.
Specifically for versions 3.7 and newer of RabbitMQ, the --formatter flag is used to output JSON, while in versions before that, the -q flag is added to prevent unnecessary output to be printed and reduce parsing errors.
The _exec method has been refactored to allow the called to decide whether or not it wants an error to immediately cause the execution to stop, or if the error should be returned and handled on a higher level. This is done to allow the module the try to check for the version of the daemon in multiple different ways.
This has been tested with the following RabbitMQ versions:
This PR is a refactoring of the RabbitMQ User module so that in the beginning of every operation it checks the version of the daemon and then, whenever possible, adds flags to the rabbitmqctl so that the output is a JSON document which can then be parsed in an easier and less "hacky" way. It is a more permanent solution relative to this PR.
Specifically for versions 3.7 and newer of RabbitMQ, the --formatter flag is used to output JSON, while in versions before that, the -q flag is added to prevent unnecessary output to be printed and reduce parsing errors.
The _exec method has been refactored to allow the called to decide whether or not it wants an error to immediately cause the execution to stop, or if the error should be returned and handled on a higher level. This is done to allow the module the try to check for the version of the daemon in multiple different ways.
This has been tested with the following RabbitMQ versions:
All versions where deployed on an Ubuntu 18.04 Vagrant VM using an Ansible script. Samples of the command outputs have been added in the rabbitmq_user_fixtures.py file.
Tests have been expanded with output from the daemon process from various versions. Now tests cover both the behavior of the module but also the parsing of input.
A small issue has also been fixed, where the module is performing more operations than needed when changing the policies of a vhost. Specifically, if a user's policy is changing, then it was first deleted and then added again. In the current PR this is changed to only a single set operation that overwrites the previous policy.
In 3.7.* versions of RabbitMQ, a weird issue was discovered, where rabbitmqctl would return unicode codes instead of the actual characters. This was fixed by checking the contents of the output and if they are integers to be converted into the unicode characters. No better way was found to solve this.
As mentioned previously, this was tested using Vagrant and two simple Ansible scripts:
Author: ptzianos
from https://github.com/ansible/ansible/pull/66876
SUMMARY
This PR is a refactoring of the RabbitMQ User module so that in the beginning of every operation it checks the version of the daemon and then, whenever possible, adds flags to the
rabbitmqctl
so that the output is a JSON document which can then be parsed in an easier and less "hacky" way. It is a more permanent solution relative to this PR. Specifically for versions 3.7 and newer of RabbitMQ, the--formatter
flag is used to output JSON, while in versions before that, the-q
flag is added to prevent unnecessary output to be printed and reduce parsing errors. The_exec
method has been refactored to allow the called to decide whether or not it wants an error to immediately cause the execution to stop, or if the error should be returned and handled on a higher level. This is done to allow the module the try to check for the version of the daemon in multiple different ways. This has been tested with the following RabbitMQ versions:SUMMARY
This PR is a refactoring of the RabbitMQ User module so that in the beginning of every operation it checks the version of the daemon and then, whenever possible, adds flags to the
rabbitmqctl
so that the output is a JSON document which can then be parsed in an easier and less "hacky" way. It is a more permanent solution relative to this PR. Specifically for versions 3.7 and newer of RabbitMQ, the--formatter
flag is used to output JSON, while in versions before that, the-q
flag is added to prevent unnecessary output to be printed and reduce parsing errors. The_exec
method has been refactored to allow the called to decide whether or not it wants an error to immediately cause the execution to stop, or if the error should be returned and handled on a higher level. This is done to allow the module the try to check for the version of the daemon in multiple different ways. This has been tested with the following RabbitMQ versions:All versions where deployed on an Ubuntu 18.04 Vagrant VM using an Ansible script. Samples of the command outputs have been added in the
rabbitmq_user_fixtures.py
file. Tests have been expanded with output from the daemon process from various versions. Now tests cover both the behavior of the module but also the parsing of input. A small issue has also been fixed, where the module is performing more operations than needed when changing the policies of a vhost. Specifically, if a user's policy is changing, then it was first deleted and then added again. In the current PR this is changed to only a singleset
operation that overwrites the previous policy.Fixes #48890, addresses final part of #29281
ISSUE TYPE
COMPONENT NAME
lib/ansible/modules/messaging/rabbitmq/rabbitmq_user.py
ADDITIONAL INFORMATION
In 3.7.* versions of RabbitMQ, a weird issue was discovered, where
rabbitmqctl
would return unicode codes instead of the actual characters. This was fixed by checking the contents of the output and if they are integers to be converted into the unicode characters. No better way was found to solve this. As mentioned previously, this was tested using Vagrant and two simple Ansible scripts:all_versions.yml
rabbitmq.yml