ansible-collections / community.mongodb

MongoDB Ansible Collection
http://galaxy.ansible.com/community/mongodb
GNU General Public License v3.0
107 stars 72 forks source link

fact cache plugin is not working with pymongo 4.6.1 #627

Closed rooso closed 8 months ago

rooso commented 8 months ago
SUMMARY

Fact caching with MongoDB fact cache plugin community.mongodb.mongodb is not working with pymongo 4.6.1. According to the issues https://github.com/ansible-collections/community.mongodb/issues/423 and https://github.com/ansible-collections/community.mongodb/issues/424 this should already been fixed (?).

With pymongo 3.12.2 everything works fine.

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
ansible [core 2.15.8]
COLLECTION VERSION
Collection        Version
----------------- -------
community.mongodb 1.6.3
CONFIGURATION
CACHE_PLUGIN(/etc/ansible/ansible.cfg) = community.mongodb.mongodb
CACHE_PLUGIN_CONNECTION(/etc/ansible/ansible.cfg) = mongodb://demo:demo@p-vm-demo-001:27017
CACHE_PLUGIN_TIMEOUT(/etc/ansible/ansible.cfg) = 3600
CONFIG_FILE() = /etc/ansible/ansible.cfg
DEFAULT_HOST_LIST(/etc/ansible/ansible.cfg) = ['/mnt/data/awx/projects/awx/inventories']
DEFAULT_INVENTORY_PLUGIN_PATH(/etc/ansible/ansible.cfg) = ['/home/demo/.ansible/collections/ansible_collections/demo/sysops/plugins/inventory']
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/etc/ansible/ansible.cfg) = ['demo.sysops.budibase', 'yaml']
PAGER(env: PAGER) = less
OS / ENVIRONMENT

Rocky Linus 8 on WSL2

STEPS TO REPRODUCE
ansible -m setup demoserver
EXPECTED RESULTS

Facts should be successfully cached in MongoDB

ACTUAL RESULTS
ansible [core 2.15.8]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/demo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/demo/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/demo/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/demo/.local/bin/ansible
  python version = 3.9.18 (main, Nov 18 2023, 01:00:14) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3.9)
  jinja version = 3.1.3
  libyaml = True
Using /etc/ansible/ansible.cfg as config file
Parsed /mnt/data/awx/projects/awx/inventories/budibase.yml inventory source with ansible_collections.demo.sysops.plugins.inventory.budibase plugin
ansible_collections.demo.sysops.plugins.inventory.budibase declined parsing /mnt/data/awx/projects/awx/inventories/groups.yml as it did not pass its verify_file() method
Parsed /mnt/data/awx/projects/awx/inventories/groups.yml inventory source with yaml plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
ERROR! Unexpected Exception, this is probably a bug: 'Collection' object is not callable. If you meant to call the 'count' method on a 'Collection' object it is failing because no such method exists.
the full traceback was:

Traceback (most recent call last):
  File "/home/demo/.local/lib/python3.9/site-packages/ansible/cli/__init__.py", line 659, in cli_executor
    exit_code = cli.run()
  File "/home/demo/.local/lib/python3.9/site-packages/ansible/cli/adhoc.py", line 190, in run
    result = self._tqm.run(play)
  File "/home/demo/.local/lib/python3.9/site-packages/ansible/executor/task_queue_manager.py", line 351, in run
    play_return = strategy.run(iterator, play_context)
  File "/home/demo/.local/lib/python3.9/site-packages/ansible/plugins/strategy/linear.py", line 180, in run
    task_vars = self._variable_manager.get_vars(play=iterator._play, host=host, task=task,
  File "/home/demo/.local/lib/python3.9/site-packages/ansible/vars/manager.py", line 310, in get_vars
    facts = wrap_var(self._fact_cache.get(host.name, {}))
  File "/usr/lib64/python3.9/_collections_abc.py", line 763, in get
    return self[key]
  File "/home/demo/.local/lib/python3.9/site-packages/ansible/vars/fact_cache.py", line 31, in __getitem__
    if not self._plugin.contains(key):
  File "/home/demo/.local/lib/python3.9/site-packages/ansible_collections/community/mongodb/plugins/cache/mongodb.py", line 185, in contains
    return bool(collection.count({'_id': self._make_key(key)}))
  File "/home/demo/.local/lib/python3.9/site-packages/pymongo/collection.py", line 3507, in __call__
    raise TypeError(
TypeError: 'Collection' object is not callable. If you meant to call the 'count' method on a 'Collection' object it is failing because no such method exists.
rhysmeister commented 8 months ago

Tests are still pinned to 3.12.2...

https://github.com/ansible-collections/community.mongodb/blob/621db961000a6b3b5dc65114159373e3a352756d/.github/workflows/mongodb-cache.yml#L98

rhysmeister commented 8 months ago

Fixed in https://github.com/ansible-collections/community.mongodb/pull/631

rhysmeister commented 8 months ago

Released in 1.7.1

rooso commented 8 months ago

@rhysmeister thanks a lot for this quick fix 😃