HiveBrain v1.2.0
Get Started
← Back to all entries
debugMinor

Ansible playbook error: Collection' object is not callable

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
errorcollectioncallableplaybookobjectnotansible

Problem

I am learning ansible on my local vagrant vm machine and I am setting up mongodb using ansible and I keep getting the error:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'Collection' object is not callable. If you meant to call the 'authenticate' method on a 'Database' object it is failing because no such method exists.
fatal: [192.168.56.11]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 192.168.56.11 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1640759955.2153473-3678-226245830655855/AnsiballZ_mongodb_user.py\", line 107, in \r\n    _ansiballz_main()\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1640759955.2153473-3678-226245830655855/AnsiballZ_mongodb_user.py\", line 99, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1640759955.2153473-3678-226245830655855/AnsiballZ_mongodb_user.py\", line 47, in invoke_module\r\n  ...


The anisble playbook configuration:

```
# tasks file for mongodb
  • include_vars: secrets.yml
  • name: Installing mongodb


apt:
name: mongodb
state: present
  • name: Start and enable the engine


service:
name: mongodb
state: started
enabled: yes
  • name: Configure Mongodb to accept outside connections


lineinfile:
path: /etc/mongodb.conf
regexp: '^#?bind_ip = 127.0.0.1'
line: '#bind_ip = 127.0.0.1'
notify:
- restart mongodb
  • name: Update Ubuntu


apt: update_cache=yes force_apt_get=yes cache_valid_time=3600
  • name: Install Python pip


apt:
name: python3-pip
state: present
  • name: Install pymongo package


pip:
name: pymongo
state: present
  • name: Is authentication enabled?


command: grep "^auth = true" /etc/mongodb.conf
register: auth
ignore_errors: yes
  • name: Add an administrator to the db


mongodb_user:
database: admin
nam

Solution

Note: this answer will very likely and quickly become obsolete when a new version of the community.mongodb collection is released

The current version (i.e. v1.3.2 at time of this writing) is not compatible with the python module pymongo version 4.x. You need to downgrade the library to version 3.x until the collection is fixed.

The current latest commit on the collection master branch is actually fixing the library version to v3.12.2 but has not yet been relased. Hopefully this will soon make it into a patch version for the collection.

In the mean time, it seems that the developers have already started a branch for pymongo4 compatibiliy. There is also a specific issue related to this problem.

Context

StackExchange DevOps Q#15220, answer score: 3

Revisions (0)

No revisions yet.