Hello, I have started development of an Ansible module to insert a document into a MongoDB database. It's over at https://github.com/ansible-collections/community.mongodb/
When a MongoDB document is inserted, without providing a value for _id, an Object ID is created automatically and returned. When this happens I get the following error... An exception occurred during task execution. To see the full traceback, use > -vvv. The error was: TypeError: Value of unknown type: <class > 'bson.objectid.ObjectId'>, 5ec14572cce378f1d3df48eb > 665 > fatal: [testhost]: FAILED! => {"changed": false, "module_stderr": > "Traceback (most recent call last):\n File > \"/root/.ansible/tmp/ansible-tmp-1589724530.3062885-3682-27933782860899/AnsiballZ_mongodb_document.py\", > > line 143, in <module>\n _ansiballz_main()\n File > \"/root/.ansible/tmp/ansible-tmp-1589724530.3062885-3682-27933782860899/AnsiballZ_mongodb_document.py\", > > line 135, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, > ANSIBALLZ_PARAMS)\n File > \"/root/.ansible/tmp/ansible-tmp-1589724530.3062885-3682-27933782860899/AnsiballZ_mongodb_document.py\", > > line 81, in invoke_module\n > runpy.run_module(mod_name='ansible_collections.community.mongodb.plugins.modules.mongodb_document', > > init_globals=None, run_name='__main__', alter_sys=True)\n File > \"/usr/lib/python3.6/runpy.py\", line 205, in run_module\n return > _run_module_code(code, init_globals, run_name, mod_spec)\n File > \"/usr/lib/python3.6/runpy.py\", line 96, in _run_module_code\n > mod_name, mod_spec, pkg_name, script_name)\n File > \"/usr/lib/python3.6/runpy.py\", line 85, in _run_code\n exec(code, > run_globals)\n File > \"/tmp/ansible_mongodb_document_payload_oe81u9jo/ansible_mongodb_document_payload.zip/ansible_collections/community/mongodb/plugins/modules/mongodb_document.py\", > > line 483, in <module>\n File > \"/tmp/ansible_mongodb_document_payload_oe81u9jo/ansible_mongodb_document_payload.zip/ansible_collections/community/mongodb/plugins/modules/mongodb_document.py\", > > line 479, in main\n File > \"/tmp/ansible_mongodb_document_payload_oe81u9jo/ansible_mongodb_document_payload.zip/ansible/module_utils/basic.py\", > > line 2045, in exit_json\n File > \"/tmp/ansible_mongodb_document_payload_oe81u9jo/ansible_mongodb_document_payload.zip/ansible/module_utils/basic.py\", > > line 2038, in _return_formatted\n File > \"/tmp/ansible_mongodb_document_payload_oe81u9jo/ansible_mongodb_document_payload.zip/ansible/module_utils/basic.py\", > > line 413, in remove_values\n File > \"/tmp/ansible_mongodb_document_payload_oe81u9jo/ansible_mongodb_document_payload.zip/ansible/module_utils/basic.py\", > > line 396, in _remove_values_conditions\nTypeError: Value of unknown type: > <class 'bson.objectid.ObjectId'>, 5ec14572cce378f1d3df48eb\n", > "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the > exact error", "rc": 1} If I specify an integer value for the _id field Ansible doesn't complain. The problem line of code is the following... inserted_id = deepcopy(str(client[database][collection].insert_one(document ).inserted_id)) The deepcopy and str cast were attempts to prevent the problem but Ansible still complains. I think this is a problem specific to something in Ansible. There's probably not much point in a mongodb_document module if I can't support using a BSON ObjectId. Would anyone have a clue what this might be and if I can get around it? Cheers, Rhys -- You received this message because you are subscribed to the Google Groups "Ansible Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-devel/121cf0c7-eae1-4d6e-a167-02bdac7aef82%40googlegroups.com.