Source code to create a custom AWX execution environment with customized Python modules and Ansible collections.
It is recommended to setup a virtual python environment to ensure it does not interfere with the local Python environment.
To setup a virtual environment ansible-builder
run the following commands:
mkdir -p ~/venv/ansible-builder
python3 -m venv ~/venv/ansible-builder
source ~/venv/ansible-builder/bin/activate
At first startup install some required modules in the venv:
pip3 install ansible-builder==3.0.0
pip3 uninstall --yes ansible-runner && pip3 install ansible-runner==2.3.3
The execution environment is configured via the following files:
- execution-environment.yml - this file contains the execution environment definition with the build instructions for the images being used to create the Dockerfile for the execution environment.
- requirements.yml - this file lists the Ansible collections being installed in the execution environment
- requirements.txt - this file lists the Python modules being installed in the execution environment
- bindep.txt - This file lists the rpm packages being installed in the image
- ansible.cfg - This file is optional and will be the default ansible.cfg for the execution environment
Build the image for the execution environment (make sure that the proper python env has been activated) by running:
ansible-builder build --tag <registry-host>/<registry-library>/<image>:<tag> --context ./context --container-runtime podman --file execution-environment.yml --prune-images --verbosity 3 --build-arg PKGMGR=/usr/bin/microdnf
for example:
ansible-builder build --tag localhost/hhue/cog-awx-custom-ee:0.0.1 --context ./context --container-runtime podman --file execution-environment.yml --prune-images --verbosity 3 --build-arg PKGMGR=/usr/bin/microdnf
The output of the ansible-builder
command is a Docker image which is created locally. To use the image in AWX you need to
- Tag the image for the Docker registry you are using
- Push the image to your Docker registry
The following is a sample configuration of the execution environment in AWX:
https://github.com/ansible/awx
https://github.com/ansible/awx-operator
https://github.com/ansible/awx/blob/devel/INSTALL.md
https://github.com/ansible/awx/blob/devel/docs/execution_environments.md
https://www.linkedin.com/pulse/creating-custom-ee-awx-phil-griffiths
https://docs.ansible.com/automation-controller/latest/html/userguide/ee_reference.html
https://weiyentan.github.io/2021/creating-execution-environments/