Ansible builder failing on new host

After working on my dev environment I am starting to get things going in our prod. I need to build the EE from a jump host and deploy it to AAP. However I am running into issues.
This is the error I am getting from the ansible-builder job:

Installing collected packages: zipp, ptyprocess, lockfile, pyyaml, python-daemon, pexpect, packaging, importlib-metadata, ansible-runner
Successfully installed ansible-runner-2.4.2 importlib-metadata-6.2.1 lockfile-0.12.2 packaging-25.0 pexpect-4.9.0 ptyprocess-0.7.0 python-daemon-3.1.2 pyyaml-6.0.3 zipp-3.23.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.3.1; however, version 25.3 is available.
You should consider upgrading via the '/usr/bin/python3.9 -m pip install --upgrade pip' command.
--> 9c6b1dd076fe
[1/4] STEP 29/29: RUN alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 0
--> b72057092dd8
[4/4] STEP 1/23: FROM b72057092dd8bd0beee7ffe9a5dcb38ed0f0a6221fb07bf780b57581fa7043f3 AS final
[4/4] STEP 2/23: ENV PIP_BREAK_SYSTEM_PACKAGES=1
--> 05747d1eb3ac
[4/4] STEP 3/23: ARG EE_BASE_IMAGE
--> 0a944f1a97ea
[4/4] STEP 4/23: ARG PYCMD
--> 1d741b59abdc
[4/4] STEP 5/23: ARG PYPKG
--> b42e4e13d5fd
[4/4] STEP 6/23: ARG PKGMGR_PRESERVE_CACHE
--> 5ed6d12467fd
[4/4] STEP 7/23: ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS
--> 9651ada4dc12
[4/4] STEP 8/23: ARG ANSIBLE_GALAXY_CLI_ROLE_OPTS
--> 90fe2e37aac3
[4/4] STEP 9/23: ARG ANSIBLE_INSTALL_REFS
--> 309f0db56d2c
[4/4] STEP 10/23: ARG PKGMGR
--> 7b367c824fa4
[4/4] STEP 11/23: RUN /output/scripts/check_ansible $PYCMD
+ PYCMD=/usr/bin/python3.9
+ '[' -z /usr/bin/python3.9 ']'
+ '[' '!' -x /usr/bin/python3.9 ']'
+ ansible --version
ansible [core 2.15.13]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.11/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.13 (main, Aug 21 2025, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-11)] (/usr/bin/python3.11)
  jinja version = 3.1.6
  libyaml = True
+ '[' 0 -ne 0 ']'
+ ansible-runner --version
2.4.2
+ '[' 0 -ne 0 ']'
+ /usr/bin/python3.9 -c 'import ansible ; import ansible_runner'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ansible'
+ '[' 1 -ne 0 ']'
+ cat
**********************************************************************
ERROR - Missing Ansible or Ansible Runner for selected Python

  An Ansible and/or Ansible Runner installation cannot be found in
  the final builder image using the following Python interpreter:

    /usr/bin/python3.9

  Ansible and Ansible Runner must be installed in the final image and
  available to the selected Python interpreter. If you are using a
  recent enough version of the execution environment file, you may use
  the 'dependencies.ansible_core' configuration option to install
  Ansible and the 'dependencies.ansible_runner' configuration option
  to install Ansible Runner. You can also use 'additional_build_steps'
  to manually do this yourself. Alternatively, use a base image with
  Ansible and Ansible Runner already installed.
**********************************************************************
+ exit 1
[2/4] STEP 1/16: FROM b72057092dd8bd0beee7ffe9a5dcb38ed0f0a6221fb07bf780b57581fa7043f3 AS galaxy
[2/4] STEP 2/16: ARG EE_BASE_IMAGE
Error: building at STEP "RUN /output/scripts/check_ansible $PYCMD": while running runtime: exit status 1

Here is my execution-environment.yml

---
version: 3

dependencies:
  galaxy: requirements.yml
  python: requirements.txt
  system: bindep.txt
  python_interpreter:
    package_system: python3.9
    python_path: /usr/bin/python3.9
  ansible_runner:
    package_pip: ansible-runner

options:
  package_manager_path: /usr/bin/microdnf

images:
  base_image:
    #    name: nexus.example.com:9093/ansible-automation-platform-25/ee-minimal-rhel9:latest
    name: registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel9:latest
      #name: 'nexus.example.com:9093/ubi9/python-311:latest'

additional_build_files:
  - src: files/ansible.cfg  # Path to your local ansible.cfg
    dest: configs

additional_build_steps:
  append_base:
    - RUN alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 0
  prepend_base: |
    ENV http_proxy=http://INT.IP.ADDR:8080
    ENV HTTP_PROXY=${http_proxy}
    ARG http_proxy
    ENV no_proxy="127.0.0.1,::1,.example.com,10.0.0.0/8,192.168.0.0/16,172.16.0.0/12"
    ARG no_proxy
    ENV PIP_INDEX_URL="http://nexus.example.com/repository/pypi-proxy/simple"
    ARG PIP_INDEX_URL
    ENV PIP_TRUSTED_HOST="nexus.example.com"
    ARG PIP_TRUSTED_HOST
    RUN pip3 config set global.index-url http://nexus.example.com/repository/pypi-proxy/simple
    RUN pip3 config set global.trusted-host nexus.example.com
    RUN pip3 install --upgrade pip
    #    RUN pip3 install pyvmomi
  prepend_galaxy:
    - COPY _build/configs/ansible.cfg /etc/ansible/ansible.cfg

requirements.yml

---

collections:

  - name: community.general
  - name: community.vmware
  - name: vmware.vmware_rest
  - name: vmware.vmware
  - name: theforeman.foreman
  - name: venafi.machine_identity
  - name: cyberark.conjur
  - name: cyberark.pas
  - name: community.postgresql
  - name: containers.podman
  - name: ansible.controller
  - name: awx.awx
  - name: ansible.utils
  - name: community.aws

requirements.txt

pyvmomi
pypsrp
requests
setuptools
pyyaml
jinja2
jsonschema
jmespath
cryptography
pyopenssl

Hi @Fracture7144

I think this is related to how ansible-builder creates the Execution Environment (EE) container image in layers, and in the next layer it doesn’t have the ansible-core package.

To resolve this issue please can you try adding the following to your execution-environment.yml file and re-build the EE:

---
version: 3
...
dependencies:
  ansible_core:
    package_pip: ansible-core

Please keep in mind that if you need a specific version of ansible-core you should define that in your execution-environment.yml file. I have an example in my own project: home-ops/ansible/ee/execution-environment.yml at main · dbrennand/home-ops · GitHub

1 Like

This is because there are multiple Python versions installed on your image. Notice that ansible reports that it is installed in the Python 3.11.13 environment, yet you are specifying in your EE definition to use Python version 3.9. This is why builder does the “import ansible” check, to verify it can see ansible from your chosen Python where all the dependencies are installed.

You can either:

  • Use the Python (3.11) where ansible is already installed, or
  • Install ansible in your selected Python (3.9)
1 Like

But the only version installed is python3.9

This fixed it but I don’t understand why. I was creating the EE on the AAP servers in my dev environment and it worked just fine…

The initial base image definitely has Python 3.11 installed based on the output, but when you specify python_interpreter with package_system, you are installing python3.9 during the build, and that version will be used to install Python packages.

Your output from the build shows ansible (the --version output) definitely using Python 3.11:

python version = 3.11.13 (main, Aug 21 2025, 00:00:00)

You probably shouldn’t specify an older Python version in your EE definition unless there is a specific reason you need it. If you removed that python_interpreter section, I suspect things would “just work”.

ok, but now I am only able to connect to RHEL 9. It is failing on RHEL 8.

Not sure what you mean, but this seems like an entirely different issue.