-
Notifications
You must be signed in to change notification settings - Fork 88
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
AttributeError: 'NoneType' object has no attribute '__version__' #252
Comments
@ojc97 hello, welcome to the project and thank you for reporting the issue! I think it relates to psycopg2 (missed or i don't know why the interpreter doesn't see it), could you please recheck? Open the interpreter Ansible use on the target machine and try to run The issue helps spot another logical bug @hunleyd @jchancojr:
That's why it reports that object is So the solution can be, for example:
Does anyone want to pick it up? Should be an easy fix. I'd be happy to help if there are any issues. |
@Andersson007 First of all thanks for your swift reply!! I have already installed psycopg2. I will try and run |
@Andersson007 I assume this is what you meant. Doesn't work as expected though.
|
@ojc97 yep |
in case described above, that task that installs psycopg2 should be also with |
https://stackoverflow.com/questions/67013694/django-unable-to-load-psycopg2-module-python-is-also-unable-to-load-it-even-th |
I can pick this up @Andersson007! Should be able to get to it ~today or this weekend. |
@jchancojr thanks! This week or next one would be imo fine:) No rush with this |
@ojc97 when you investigate what's the reason and how to fix it, please let us know. |
added `ensure_required_libs(module)` to `get_conn_params` to ensure a meaningful error is thrown when psycopg2 is not installed. Without this change the error was; `AttributeError: 'NoneType' object has no attribute '__version__'`. Fixes ansible-collections#252
@Andersson007 I have been looking into the reasons regarding this today and i am yet to have an answer... It appears that lots of people have problems with psycopg2 on mac os. Even more with M1 ARM Macs. If you have any recommendations, id love to hear them. So far i have reinstalled, used psycopg2-binary instead, added exports as suggested here and some others... |
@ojc97 as a workaround you could try to:
|
@Andersson007 @ojc97 I am facing the same issue on a current CentOS machine. I think I have everything necessary installed such as:
but it still don't work... |
Hi all - @mschwrdtnr @Andersson007 I believe i have fixed the issues on my end...
Hope this helps. |
This appeared to be an M1 Mac specific issue. |
…in postgres.py (#253) * Update README.md to remove Ansible 2.9 & 2.10 * Update version.py comment to remove references to Ansible version 2.9 & 2.10 * Update changelog * Updated to include feedback from @Andersson007i * Fix: add call to ensure required libraries in get_conn_params added `ensure_required_libs(module)` to `get_conn_params` to ensure a meaningful error is thrown when psycopg2 is not installed. Without this change the error was; `AttributeError: 'NoneType' object has no attribute '__version__'`. Fixes #252 * add changelog fragment * Update changelog fragment based on Andrew's feedback. * change the `ensure_required_libs(module)` call to be in every module rather than just the definition for clarity. * Add ensure_required_libs to import. Was missing from my last commit. * Fix module to be self.module * Remove redundant ensure_required_libs(module) call since it's now called explicitly in each module.
@ojc97 thanks for the solution! |
I face the same issue on custom awx-ee. I can create container out of it and run
with no issues but ansible job that calls postgresql_query is failing with same error
|
@blindrood thanks for the feedback! |
@Andersson007 I understand but psycopg2 (or rather psycopg2-binary) is part of awx-ee image, it's being installed during its creation and is working as I can access it from container. You can find image here: |
@blindrood i don't know how it works, could you please explain if this image is used as a target host? |
This is ansible-runner custom image (https://github.com/ansible/ansible-runner) AWX runs ansible templates (playbooks) from inside such container to ensure reliability and reapitability. Dockerfile is generated using builder and it basically installs OS packages, install pip packages and galaxy roles. It was working for now but I had to recreate image due to issue with Cryptography and Openssl package issues after AWX upgrade.
I started facing issue with postgres templates that run postgresql_query module with error above |
@blindrood thank you for the explanation!
put
If it doesn't help, i would recommend to create an issue in ee repo |
Maybe |
Hi, I followed Your suggestion and indeed this revealed that
How I can overcome this during Docker image creation if part of it already is pip install psycopg2-binary ? |
Hi, maybe something from https://stackoverflow.com/questions/64690093/why-is-installing-python-psycopg2-on-my-docker-image-not-preventing-the-subseque will help. |
Looks like I resolved issue on my side. Suspicious for me was that errors refer to python3.6 while I'm explicitly installing and using python3.8. dnf is not reporting python3.6 to be installed but files are there. Enabling debug in AWX I noticed that Ansible is refering to python at /usr/libexec/platform-python which is symbolic link to python3.6 binary. I changed this symlink to point to current pytho
and all started working. I think this is a bug in ansible-runner base image and I'll report this there. |
@blindrood thanks for the feedback!
Does make sense. You're welcome! |
closed via #253 |
SUMMARY
When using the community.postgresql.postgresql_user or community.postgresql.postgresql_schema ansible modules, I am facing a python stacktrace which has the error "AttributeError: 'NoneType' object has no attribute 'version'".
I have looked online and seen that this could be due to 'psycopg2' being missing but I have added an ansible step to ensure this is present.
Any help greatly appreciated.
ISSUE TYPE
COMPONENT NAME
community.postgresql.postgresql_user
community.postgresql.postgresql_schema
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
MacOS 12.3.1
Database is on AWS RDS Postgres.
STEPS TO REPRODUCE
EXPECTED RESULTS
Playbook should run and configure users.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: