Ansible not working after python version upgrade

I tried to update the underlying python. I reinstalled ansible-core via pip3 and tried to run an ansible playbook:

$ ansible-playbook -i ansible_inventory.ini playbooknme.yaml --checkmode
ERROR! Unexpected Exception, this is probably a bug: module 'ansible.constants' has no attribute 'CONTROLLER_PYTHON_WARNING'
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-playbook", line 76, in <module>
    if C.CONTROLLER_PYTHON_WARNING and not _PY38_MIN:
AttributeError: module '' has no attribute 'CONTROLLER_PYTHON_WARNING'

Sadly, its an Amazon Linux 2, which only has python 3.8 in its repositories packages, which I installed.
I already removed the system Ansible version, which aws provided.
But that’s not working. Maybe smb here has an idea, what to do.

There’s a similar closed issue over on the Ansible github.

The discussion over there implies this is a broken python or ansible installation, and mentions a conflict between the system python and user python environments.

Something I learned is don’t mess with system python environments. Instead, install whatever version of python you want to use and then make a virtual environment of the python version you want.

That will allow you to isolate a lot of python dependencies and requirements to just that virtual environment.

1 Like