Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.12: RawConfigParser object has no attribute 'readfp' #668

Closed
whzd opened this issue Aug 6, 2024 · 1 comment
Closed

Python3.12: RawConfigParser object has no attribute 'readfp' #668

whzd opened this issue Aug 6, 2024 · 1 comment

Comments

@whzd
Copy link

whzd commented Aug 6, 2024

SUMMARY

Running a community.mongodb.mongodb_user task fails with the message "Unable to connect to database: 'RawConfigParser' object has no attribute 'readfp'".

readfp() was replaces with read_file() as stated on https://docs.python.org/3/library/configparser.html#configparser.ConfigParser.read_file

ISSUE TYPE
  • Bug Report
COMPONENT NAME

mongodb_common.py

ANSIBLE VERSION
core 2.16.3
COLLECTION VERSION
Collection        Version
----------------- -------
community.general 8.3.0
CONFIGURATION
CONFIG_FILE() = /home/whzd/infrastructure/configuration/ansible.cfg
DISPLAY_SKIPPED_HOSTS(/home/whzd/infrastructure/configuration/ansible.cfg) = False
EDITOR(env: EDITOR) = nvim
PAGER(env: PAGER) = less

OS / ENVIRONMENT

OS: NixOS 24.05.20240228.9099616 (Uakari) x86_64

STEPS TO REPRODUCE

Create the admin user for a new mongodb instance

- name: Config admin user
  community.mongodb.mongodb_user:
    database: admin
    user: "{{ lookup('vars', cloud + env + '_mongo_db_user') }}"
    password: "{{ lookup('vars', cloud + env + '_mongo_db_pw') }}"
    roles: userAdminAnyDatabase, readWriteAnyDatabase
EXPECTED RESULTS

The task will fail with the provided message.

ACTUAL RESULTS
TASK [mongodb : Config admin role] **********************************************************************************************************************************************************
task path: /home/whzd/infrastructure/configuration/roles/mongodb/tasks/main.yml:64
The full traceback is:
  File "/tmp/ansible_community.mongodb.mongodb_user_payload_p8efmq2m/ansible_community.mongodb.mongodb_user_payload.zip/ansible_collections/community/mongodb/plugins/modules/mongodb_user.py", line 362, in main
    client = mongo_auth(module, client, directConnection=directConnection)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/ansible_community.mongodb.mongodb_user_payload_p8efmq2m/ansible_community.mongodb.mongodb_user_payload.zip/ansible_collections/community/mongodb/plugins/module_utils/mongodb_common.py", line 328, in mongo_auth
    mongocnf_creds = load_mongocnf()
                     ^^^^^^^^^^^^^^^
  File "/tmp/ansible_community.mongodb.mongodb_user_payload_p8efmq2m/ansible_community.mongodb.mongodb_user_payload.zip/ansible_collections/community/mongodb/plugins/module_utils/mongodb_common.py", line 60, in load_mongocnf
    config.readfp(open(mongocnf))
    ^^^^^^^^^^^^^
fatal: [host]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "atlas_auth": false,
            "auth_mechanism": null,
            "connection_options": null,
            "create_for_localhost_exception": null,
            "database": "admin",
            "login_database": "admin",
            "login_host": "localhost",
            "login_password": null,
            "login_port": 27017,
            "login_user": null,
            "name": "admin",
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "replica_set": null,
            "roles": [
                "userAdminAnyDatabase",
                " readWriteAnyDatabase"
            ],
            "ssl": false,
            "ssl_ca_certs": null,
            "ssl_cert_reqs": "CERT_REQUIRED",
            "ssl_certfile": null,
            "ssl_crlfile": null,
            "ssl_keyfile": null,
            "ssl_pem_passphrase": null,
            "state": "present",
            "strict_compatibility": true,
            "update_password": "always",
            "user": "admin"
        }
    },
    "msg": "Unable to connect to database: 'RawConfigParser' object has no attribute 'readfp'"
}

@rhysmeister
Copy link
Collaborator

Thanks @whzd , Fix in #669

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants