How to add option for pip3 install command in execution-environment.yml?

,

I am using AAP execution environment feather and trying to build a customized image for that. I have python packages need to be installed to the custom image. I have them listed in requierments.txt file. I believe ansible-builder uses pip3 to install them. But how can I pass some options? For example, I want to install XYZ python package. I can run:

pip3 install --user XYZ==2.1.0.0

In execution-environment.yml, how can I achieve this? If I do

additional_build_steps:
prepend_base: RUN pip3 install --user XYZ

What is the impact to XYZ I listed in requirements.txt?

Thanks,

J

1 Like

Hi jzhang2006,

If you already have a requirements.txt file then you can pass that directly into your execution-environment.yml by using the dependencies option. I’ve always kept it in the same root folder as the execution-environment.yml so not sure if it supports paths. Example below:

version: 3

images:
  base_image:
    name: 'registry.redhat.io/ansible-automation-platform-25/ee-minimal-rhel9:latest'

dependencies:
  galaxy: requirements.yml
  python: requirements.txt

The ansible-builder docs have an example that includes a lot of formatting variations. Execution environment definition — Ansible Builder Documentation

I have broken out to a shell/container commands under the addtional_build_steps when I needed to do something like a non-standard package location or the like but that’s not the norm in my experience. The method above has worked well for our builds.

If you’re getting a build error, feel free to post that back and I’ll be happy to take a look.

*note: updated base_image to include a real image to avoid confusion.

1 Like

Hi jzhang2006,

Apologies for the double post, just re-read your original question (will do a better job at that in the future). For other options like “–user”, I’ve had to put them in the additional_build_steps similar to what you have listed. I usually execute them in the append_final step as we’ve moved to version 3 for most of our configs. Depending on where in the build process you may need to use a different option. The link in my first post has some good references. In this example we were having issues getting pywinrm[kerberos] to install via the requirements.txt and moved to doing it after the main build steps were finished.

version: 3

images:
  base_image:
    name: 'registry.redhat.io/ansible-automation-platform-25/ee-minimal-rhel9:latest'

dependencies:
  galaxy: requirements.yml
  python: requirements.txt

additional_build_files:
  - src: krb5.conf
    dest: krb5.conf

additional_build_steps:
  append_final:
    - RUN pip3 install --upgrade pip
    - RUN pip3 install pywinrm[kerberos]
    - COPY _build/krb5.conf /etc/
1 Like

I use pip3 install -t <package_path> and it works as expected.

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

Thanks,

J

1 Like