community.mongodb
community.mongodb copied to clipboard
mongodb_status fails on Arbiter because of is_auth_enabled check
SUMMARY
If you try to get the Replication Status of Arbiter with no active authentication you get the following error:
Unable to determine if auth is enabled: Traceback (most recent call last):
pymongo.errors.NotPrimaryError: node is not in primary or recovering state, full error: {'topologyVersion': {'processId': ObjectId('6655f606ee98c67bac861bed'), 'counter': 1}, 'ok': 0.0, 'errmsg': 'node is not in primary or recovering state', 'code': 13436, 'codeName': 'NotPrimaryOrSecondary'}
The Problem seems to be here: https://github.com/ansible-collections/community.mongodb/blob/master/plugins/module_utils/mongodb_common.py#L294 When you try to execute db.adminCommand('listDatabases', 1.0) on an Arbiter ( with no authentication ) you get the error NotPrimaryOrSecondary(13436 ) and not as expected Unauthorized(13)
This looks similar to this Bug: https://github.com/ansible-collections/community.mongodb/issues/136
ISSUE TYPE
- Bug Report
COMPONENT NAME
mongodb_status
ANSIBLE VERSION
ansible [core 2.16.6]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.12/site-packages/ansible
ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)] (/usr/bin/python3)
jinja version = 3.1.4
libyaml = True
COLLECTION VERSION
ansible-galaxy collection list community.mongodb
# /usr/lib/python3.12/site-packages/ansible_collections
Collection Version
----------------- -------
community.mongodb 1.7.3
CONFIGURATION
OS / ENVIRONMENT
MongoDB 7.0.11 on RHEL9
STEPS TO REPRODUCE
- name: Get replica_set status
community.mongodb.mongodb_status:
login_host: "{{ inventory_hostname }}"
login_port: "{{ mongodb_port }}"
login_user: "{{ mongodb_admin_user }}"
login_password: "{{ mongodb_admin_default_pw }}"
replica_set: "{{ mongodb_replset_name }}"
auth_mechanism: "SCRAM-SHA-256"
poll: 6
interval: 10
EXPECTED RESULTS
mongodb_status:
changed: false
failed: false
failed_when_result: false
iterations: 1
msg: replicaset is in a converged state
replicaset:
mongodb11-test:27015: PRIMARY
mongodb21-test:27015: SECONDARY
mongodb31-test:27015: ARBITER
ACTUAL RESULTS
Unable to determine if auth is enabled: Traceback (most recent call last):
File "/tmp/ansible_community.mongodb.mongodb_status_payload_tqnr2bm4/ansible_community.mongodb.mongodb_status_payload.zip/ansible_collections/community/mongodb/plugins/module_utils/mongodb_common.py", line 294, in is_auth_enabled
myclient['admin'].command('listDatabases', 1.0)
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/database.py", line 894, in command
return self._command(
^^^^^^^^^^^^^^
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/database.py", line 743, in _command
return conn.command(
^^^^^^^^^^^^^
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/helpers.py", line 322, in inner
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/pool.py", line 968, in command
return command(
^^^^^^^^
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/network.py", line 192, in command
helpers._check_command_response(
File "/opt/dw_mongo_virtualenv/lib64/python3.11/site-packages/pymongo/helpers.py", line 217, in _check_command_response
raise NotPrimaryError(errmsg, response)
pymongo.errors.NotPrimaryError: node is not in primary or recovering state, full error: {'topologyVersion': {'processId': ObjectId('6655f606ee98c67bac861bed'), 'counter': 1}, 'ok': 0.0, 'errmsg': 'node is not in primary or recovering state', 'code': 13436, 'codeName': 'NotPrimaryOrSecondary'}