Ansible Commands Fail Due to Python Packages
Summary
When using the latest image, attempting to use ansible
or ansible-galaxy
commands results in this error:
Traceback (most recent call last):
File "/usr/local/bin/ansible-galaxy", line 5, in <module>
from ansible.cli.galaxy import main
ModuleNotFoundError: No module named 'ansible'
To see this is in action, refer to this pipeline run.
After doing some digging, the problem appears to be how this image is populating its python site packages.
In the image Dockerfile, site packages are copied from upstream to the image's python 3.11 site package directory (ref 1 and ref 2). However, the image is based off of python 3.12. As a result, anything using python such as the ansible
or ansible-galaxy
commands is lacking the required site packages.
The change from python 3.11 to python 3.12 should have included updates to the COPY commands. It appears the change was made by renovate (ref) in March.
The quick fix is to update the COPY commands to copy to 3.12 site packages, but these COPY commands are brittle and should be swapped out for something more robust. In addition to breakages like this, the upstream could change from using python 3.9 and break again. Or the packages that were installed against python 3.9 could fail to work against a python 3.12 binary. Or the site packages directory could move, etc.
A better method would be to run pip freeze
on the upstream to capture the required packages and then installing them on the image using its pip
command.
Steps to reproduce
Exec into the container and run any ansible
or ansible-galaxy
command.
What is the current bug behavior?
Commands return errors like this:
Traceback (most recent call last):
File "/usr/local/bin/ansible-galaxy", line 5, in <module>
from ansible.cli.galaxy import main
ModuleNotFoundError: No module named 'ansible'
What is the expected correct behavior?
Commands should run without error.
Relevant logs and/or screenshots
Job run of a downstream pipeline using this image ref
Possible fixes
COPY commands from when the image was python 3.11 ref 1 and ref 2
Renovate commit bumping from python 3.11 to 3.12 ref
Tasks
-
Bug has been identified and corrected within the container
Please read the Iron Bank Documentation for more info