ansible-collections / community.rabbitmq

Manage RabbitMQ with Ansible
http://galaxy.ansible.com/community/rabbitmq
Other
30 stars 46 forks source link

Suppress informational messages #148

Closed zzhanabek closed 1 year ago

zzhanabek commented 1 year ago

Hello!

I am facing an issue, which is failing idempotence. On this setting:

ansible [core 2.13.6]
  python version = 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)]
  jinja version = 3.1.2
  libyaml = False
ansible-playbook [core 2.13.6]
  python version = 3.11.0 (main, Oct 24 2022, 00:00:00) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)]
  jinja version = 3.1.2

rabbitmq_rabbit_version: 3.9.16
rabbitmq_erlang_version: 23.3.4.11
OS: rockylinux/8
Rabbitmq repo: dl.cloudsmith.io/public/rabbitmq/rabbitmq-server

Code of the failing task:

- name: Enable plugins
  rabbitmq_plugin:
    names: '{{ rabbitmq_plugin }}'
    state: enabled

Everytime this task returns changed.

In local environment I have fixed this issue by adding '-s' in this line: https://github.com/ansible-collections/community.rabbitmq/blob/0a5173b01ac27be81d98d04a86c0a94869cf8408/plugins/modules/rabbitmq_plugin.py#L122

list_output = self._exec(['list', '-E', '-m', '-s'], True) 

How it looks in current state as version 1.2.3

[root@amqp-01 ~]# rabbitmq-plugins list -E -m
Listing plugins with pattern ".*" ...
rabbitmq_management

How it will be look like with '-s' parameter

[root@amqp-01 ~]# rabbitmq-plugins list -E -m -s
rabbitmq_management

Regards, Zangar Zhanabek

Im0 commented 1 year ago

@zzhanabek thank you for reporting and providing a suggested fix. We will look to implement a fix in the next version once validated.

Im0 commented 1 year ago

@zzhanabek I've not yet been replicate the issue that you have been seeing. I raised a PR with a bit more debugging output on the integration test and the results appeared as though idempotency worked fine.

The integration tests are visible here: https://github.com/ansible-collections/community.rabbitmq/blob/main/tests/integration/targets/rabbitmq_plugin/tasks/tests.yml Do they look similar to what you're doing in your play? Any suggestions as to how I can reproduce the issue you're seeing?

2022-11-23T03:34:08.6350155Z 01:55 TASK [rabbitmq_plugin : set_fact] **********************************************
2022-11-23T03:34:08.6636798Z 01:55 ok: [testhost] => {"ansible_facts": {"plugin_name": "rabbitmq_top"}, "changed": false}
2022-11-23T03:34:08.6639048Z 01:55 
2022-11-23T03:34:08.6639555Z 01:55 TASK [rabbitmq_plugin : Enable plugin [online]] ********************************
2022-11-23T03:34:13.4593467Z 02:00 changed: [testhost] => {"changed": true, "disabled": [], "enabled": ["rabbitmq_top"]}
2022-11-23T03:34:13.4594111Z 02:00 
2022-11-23T03:34:13.4594528Z 02:00 TASK [rabbitmq_plugin : debug] *************************************************
2022-11-23T03:34:13.4901353Z 02:00 ok: [testhost] => {
2022-11-23T03:34:13.4902099Z 02:00     "result": {
2022-11-23T03:34:13.4902831Z 02:00         "changed": true,
2022-11-23T03:34:13.4903434Z 02:00         "disabled": [],
2022-11-23T03:34:13.4915582Z 02:00         "enabled": [
2022-11-23T03:34:13.4916265Z 02:00             "rabbitmq_top"
2022-11-23T03:34:13.4916879Z 02:00         ],
2022-11-23T03:34:13.4917462Z 02:00         "failed": false
2022-11-23T03:34:13.4918030Z 02:00     }
2022-11-23T03:34:13.4918558Z 02:00 }
2022-11-23T03:34:13.4918861Z 02:00 
2022-11-23T03:34:13.4919597Z 02:00 TASK [rabbitmq_plugin : Get rabbitmq-plugins output] ***************************
2022-11-23T03:34:15.5153885Z 02:02 changed: [testhost] => {"changed": true, "cmd": "rabbitmq-plugins list | grep rabbitmq_top", "delta": "0:00:01.857142", "end": "2022-11-23 03:34:15.488368", "msg": "", "rc": 0, "start": "2022-11-23 03:34:13.631226", "stderr": "", "stderr_lines": [], "stdout": "[E*] rabbitmq_top                      3.11.3", "stdout_lines": ["[E*] rabbitmq_top                      3.11.3"]}
2022-11-23T03:34:15.5155050Z 02:02 
2022-11-23T03:34:15.5155486Z 02:02 TASK [rabbitmq_plugin : Check that the plugin is enabled] **********************
2022-11-23T03:34:15.5592738Z 02:02 ok: [testhost] => {
2022-11-23T03:34:15.5593478Z 02:02     "changed": false,
2022-11-23T03:34:15.5594161Z 02:02     "msg": "All assertions passed"
2022-11-23T03:34:15.5605199Z 02:02 }
2022-11-23T03:34:15.5605528Z 02:02 
2022-11-23T03:34:15.5612622Z 02:02 TASK [rabbitmq_plugin : debug] *************************************************
2022-11-23T03:34:15.5915597Z 02:02 ok: [testhost] => {
2022-11-23T03:34:15.5916456Z 02:02     "cli_result": {
2022-11-23T03:34:15.5917130Z 02:02         "changed": true,
2022-11-23T03:34:15.5926095Z 02:02         "cmd": "rabbitmq-plugins list | grep rabbitmq_top",
2022-11-23T03:34:15.5927233Z 02:02         "delta": "0:00:01.857142",
2022-11-23T03:34:15.5927992Z 02:02         "end": "2022-11-23 03:34:15.488368",
2022-11-23T03:34:15.5928648Z 02:02         "failed": false,
2022-11-23T03:34:15.5929248Z 02:02         "msg": "",
2022-11-23T03:34:15.5929820Z 02:02         "rc": 0,
2022-11-23T03:34:15.5930505Z 02:02         "start": "2022-11-23 03:34:13.631226",
2022-11-23T03:34:15.5931154Z 02:02         "stderr": "",
2022-11-23T03:34:15.5932070Z 02:02         "stderr_lines": [],
2022-11-23T03:34:15.5932808Z 02:02         "stdout": "[E*] rabbitmq_top                      3.11.3",
2022-11-23T03:34:15.5933505Z 02:02         "stdout_lines": [
2022-11-23T03:34:15.5934182Z 02:02             "[E*] rabbitmq_top                      3.11.3"
2022-11-23T03:34:15.5934791Z 02:02         ]
2022-11-23T03:34:15.5935317Z 02:02     }
2022-11-23T03:34:15.5935836Z 02:02 }
2022-11-23T03:34:15.5936139Z 02:02 
2022-11-23T03:34:15.5936574Z 02:02 TASK [rabbitmq_plugin : Enable plugin [online] (idempotency)] ******************
2022-11-23T03:34:17.3567716Z 02:04 ok: [testhost] => {"changed": false, "disabled": [], "enabled": []}
2022-11-23T03:34:17.3576154Z 02:04 
2022-11-23T03:34:17.3576622Z 02:04 TASK [rabbitmq_plugin : debug] *************************************************
2022-11-23T03:34:17.3877300Z 02:04 ok: [testhost] => {
2022-11-23T03:34:17.3878016Z 02:04     "result": {
2022-11-23T03:34:17.3889612Z 02:04         "changed": false,
2022-11-23T03:34:17.3890635Z 02:04         "disabled": [],
2022-11-23T03:34:17.3899034Z 02:04         "enabled": [],
2022-11-23T03:34:17.3899685Z 02:04         "failed": false
2022-11-23T03:34:17.3900246Z 02:04     }
2022-11-23T03:34:17.3900774Z 02:04 }
2022-11-23T03:34:17.3901058Z 02:04 
2022-11-23T03:34:17.3901485Z 02:04 TASK [rabbitmq_plugin : Check idempotency] *************************************
2022-11-23T03:34:17.4229189Z 02:04 ok: [testhost] => {
2022-11-23T03:34:17.4229954Z 02:04     "changed": false,
2022-11-23T03:34:17.4230616Z 02:04     "msg": "All assertions passed"
2022-11-23T03:34:17.4231195Z 02:04 }
zzhanabek commented 1 year ago

Hello! I could not get any output from community.rabbitmq.rabbitmq_plugin. I noticed, how binary called and reproduced python code, so by this way I've found: Clustered rabbitmq shows message

Listing plugins with pattern ".*" ...

in output when called via

rabbitmq-plugins list -E -m

, just like in python code

list_output = self._exec(['list', '-E', '-m'], True) 
zzhanabek commented 1 year ago

My config, where I found this idempotence fail at plugins installation task

rabbitmq_plugins:
  - rabbitmq_management
rabbitmq_env_config: |
  USE_LONGNAME=true
rabbitmq_config: |
  cluster_name = amqp
  cluster_formation.peer_discovery_backend = classic_config
  {% for node in groups.amqp %}
  cluster_formation.classic_config.nodes.{{ loop.index0 + 1 }} = rabbit@{{ hostvars[node].ansible_nodename }}
  {% endfor %}

  {% for node in groups.amqp %}
  cluster_partition_handling.pause_if_all_down.nodes.{{ loop.index0 + 1 }} = rabbit@{{ hostvars[node].ansible_nodename }}
  {% endfor %}

ansible tasks code:

- name: Enable plugins
  rabbitmq_plugins:
    names: '{{ rabbitmq_plugins | join(",") }}'
    state: enabled
  when: rabbitmq_plugins | length > 0
Im0 commented 1 year ago

@zzhanabek thanks for the additional information. I'm having a hard time identifying why you're seeing this issue and I'm not. I'm wondering if it's playing up due to the clustering... we don't test in the integration testing against a cluster.

Before implementing your suggested fix I would really like to reproduce or understand what's causing the issue.

My plugins list returns this:

# rabbitmq-plugins list -E -m
Listing plugins with pattern ".*" ...
rabbitmq_management
rabbitmq_prometheus
rabbitmq_random_exchange

Is your output exactly the same other than the plugins being enabled? They look the same to me at the moment.

I might have to spin up some containers and setup a cluster to test against. I'm wondering if this is somehow related to #109

zzhanabek commented 1 year ago

@Im0 Hello!

Is your output exactly the same other than the plugins being enabled?

I ran this module and shell command against 3 different environments. Differences in OSes, Rabbitmq version, cluster and standalone modes, plugins. All testing environments showed in output:

Listing plugins with pattern ".*" ...

but version rabbitmq-server-3.7.7-1.el7 showed nothing but actual list. Idempotence tests failed in a case, where plugins list was mixed with implicitly enabled and explicitly enabled — my bad. Sorry for taking your time, and thank you for trying to help!

Im0 commented 1 year ago

@zzhanabek thanks for letting me know. I'll close this issue now but please feel free to re-open if required.