EE default ansible python module location is different from pip3 installation location

,

I am using ansible-builder 3.1.0 with redhat base image ansible-automation-platform-24/ee-supported-rhel8:1.0.0-887 to build an EE image for AAP 2.4. I am facing an issue: EE default ansible python module location is different than pip3 installation location:

EE default ansible python module location = /usr/lib/python3.9/site-packages/ansible
pip3 installed location default to: /usr/local/lib/python3.9/site-packages

My use case is to install PyU4V for a storage collection. Even PyU4V is installed from pip3 perspective but the collection can’t find it.

I tried to twist execution-environment.yml to run pip3:

RUN pip3 install -t /usr/lib/python3.9/site-packages/ansible PyU4V==10.1.0.0

The PyU4V is installed in /usr/lib/python3.9/site-packages/ansible directory but the collection still can’t find it.

I don’t think I can use PYTHONPATH with ansible-builder as it only works with a user’s shell session scope. Is there anything I am missing here?

Thanks!

J

1 Like

Try RUN pip3 install -t /usr/lib/python3.9/site-packages PyU4V==10.1.0.0

You want pip packages to be installed under site-packages, not a sub directory of it. That said, it might be better to try installing dnf install python3.9-PyU4V if it exists in AppStream.

1 Like

Given the Python module in question I assume you are wanting to use the dell.powermax collection in the EE. The following execution-environment.yml produces an EE that contains PyU4V <= 10.1.0.2 which is required by the code within the module.

---
additional_build_steps:
  append_base:
    - RUN $PYCMD -m pip install --upgrade pip

dependencies:
  galaxy: |-
    collections:
      - name: dellemc.powermax
        version: 3.1.0
  python:
    - PyU4V <= 10.1.0.2

images:
  base_image:
    name: registry.redhat.io/ansible-automation-platform-24/ee-supported-rhel8:1.0.0-887

options:
  package_manager_path: /usr/bin/microdnf

version: 3

The collection does have a requirements.txt but it doesn’t limit the version that is installed so as of right now if you use PyPi you get a version that’s newer than what is supported.

    "msg": "PyU4V 10.2.0.2 is not supported by this module.Minimum supported version is : 9.1.2.0 and less than 10.1.0.2 "

We use the additional Python requirement to constrain it back to a version that will work with the collection.

I posted an issue that should help to resolve this. Also let me know here if you are trying to install this module but not use the dell.powermax collection.

2 Likes

Hi Caleb,

I follow your suggestion and fixed it:

RUN pip3 install -t /usr/lib/python3.9/site-packages PyU4V==10.1.0.0

The PyU4V is installed in /usr/lib/python3.9/site-packages. My playbook pre-task verified the installation by pip3 show PyU4V and it suceeds. But my followed task that depends on this package failed due to not finding it. Here is the playbook snippet:


  • name: Create Storage Group
    hosts: create_storagegroup
    connection: local
    gather_facts: false

    pre_tasks:

    • name: Check whether a package called PyU4U is installed
      ansible.builtin.command: ‘pip3 show PyU4V’
      ignore_errors: true
      changed_when: result.rc != 0 # ← Uses the return code to define when the task has changed.
      register: result

    • name: Print out package installation status
      ansible.builtin.debug:
      msg: “{{ result }}”

    roles:

    • create_storagegroup

The error shows: “Ansible modules for PowerMax require the PyU4V python library to be installed. Install the library before using these modules.”

Thanks,

J

Hi Tim,

Yes, I am working with dell.powermax collection. My execution-environment.yml is very similar to yours. It still not working.


version: 3

dependencies:
galaxy: files/requirements.yml
python:
- PyU4V <= 10.1.0.2
system: files/bindep.txt

images:
base_image:
name: ‘registry.redhat.io/ansible-automation-platform-24/ee-supported-rhel8:1.0.0-887

additional_build_steps:
append_base:
- RUN $PYCMD -m pip install --upgrade pip

use microdnf as the base image is minimal one

options:
package_manager_path: /usr/bin/microdnf

The requiremens.yml under files directory:


collections:

Install Dell EMC Ansible modules for PowerMax

As this ee file does not force PyU4V to be installed in /usr/lib/python3.9/site-packages. It goes to
/usr/local/lib/python3.9/site-packages. AAP log shows:

ansible-playbook [core 2.15.13]
config file = /etc/ansible/ansible.cfg
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python3.9/site-packages/ansible
ansible collection location = /runner/requirements_collections:/root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible-playbook
python version = 3.9.20 (main, Sep 26 2024, 20:59:47) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] (/usr/bin/python3.9)
jinja version = 3.1.5
libyaml = True
Using /etc/ansible/ansible.cfg as config file


“stdout_lines”: [
“Name: PyU4V”,
“Version: 10.1.0.2”,
“Summary: A Python library for use with Dell EMC’s Unisphere for PowerMax REST API.”,
“Home-page: GitHub - dell/PyU4V: PyU4V is a Python module that simplifies interaction with the Unisphere for PowerMax REST API. It wraps REST calls with simple APIs that abstracts the HTTP request and response handling.”,
“Author: Dell Inc. or its subsidiaries”,
“Author-email: helen.walsh@dell.com”,
“License: Apache 2.0”,
Location: /usr/local/lib/python3.9/site-packages”,
“Requires: prettytable, requests, six, sphinx-rtd-theme, urllib3”,
“Required-by: #N/A”
]

The create_storagegroup role failed due to: “Ansible modules for PowerMax require the PyU4V python library to be installed. Install the library before using these modules”

By the way, the play runs totally fine if I did it on a VM (not with AAP). It only fails in AAP (which is installed with containerized way).

Thanks,

J

Try installing the Python dependency the way show vs using pip commands.

Hi Tim,

Yes, I did what you showed and it is the same results. What version of ansible-builder you used? Do you see ’ ansible python module location = /usr/lib/python3.9/site-packages/ansible’ in AAP template output?

J

I used ansible-builder==3.1.0. The way I express the dependencies will allow ansible-builder to specify the correct Python installation that is related to ansible. I too see ansible using /usr/bin/python3.9 (aka /usr/lib/python3.9/site-packages)

Avoiding pip3 in the execution-environment.yml is probably a good idea especially since we’re given a method to directly express Python dependencies. That said I can confirm that both /usr/lib<64> and /usr/local/lib<64> are both searched. From within the container you can see the search path for the Python modules:

bash-4.4$ python3 -m site   
sys.path = [
    '/runner',
    '/usr/lib64/python39.zip',
    '/usr/lib64/python3.9',
    '/usr/lib64/python3.9/lib-dynload',
    '/usr/local/lib64/python3.9/site-packages',
    '/usr/local/lib/python3.9/site-packages',
    '/usr/lib64/python3.9/site-packages',
    '/usr/lib/python3.9/site-packages',
]
USER_BASE: '/runner/.local' (doesn't exist)
USER_SITE: '/runner/.local/lib/python3.9/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

Prior to uploading your built image your registry and launched via AAP2 you can test it with ansible-navigator or podman directly.

1 Like

It’s working now. I missed adding ansible_python_interpreter: ‘/usr/bin/python3’ to the inventory. EE stuffs are all good.

Thanks a lot for the help!

J

1 Like