If you have upgraded to awx 19 you may need to execute your jobs with specific awx-ee image. In this article we will go through the steps of building this custom image with ansible-builder.
what you need:
A docker environnement
python3
An Image Registry (dockerhub for example)
AWX on k8s (microk8s or minikube)
Ansible-builder install and config
Create a clean python virtual environment:
#Install pip if not present
sudo apt install python3-pip
mkdir ~/ansible-builder && cd ~/ansible-builder
python3 -m venv builder
source builder/bin/activate
Install the components:
pip install wheel
pip install ansible
pip install ansible-builder
Create the config execution-environment.yml :
---
version: 1
dependencies:
galaxy: requirements.yml
python: requirements.txt
system: bindep.txt
additional_build_steps:
append:
- RUN alternatives --set python /usr/bin/python3
- COPY --from=quay.io/project-receptor/receptor:0.9.7 /usr/bin/receptor /usr/bin/receptor
- RUN mkdir -p /var/run/receptor
- ADD run.sh /run.sh
- CMD /run.sh
- USER 1000
- RUN git lfs install
Create the requirements.yml and add the ansible collections that you need :
---
collections:
- community.general
Create the requirements.txt and add the python packages that you need:
urllib3
git+https://github.com/ansible/ansible-builder.git@devel#egg=ansible-builder
Create the bindep.txt file
python38-devel [platform:rpm compile]
subversion [platform:rpm]
subversion [platform:dpkg]
git-lfs [platform:rpm]
Create the context/run.sh script :
#! /bin/bash
ansible-runner worker --private-data-dir=/runner
Add the execution rights to the script :
chmod +x context/run.sh
Build the EE Image
ansible-builder build --tag cisel/awx-ee:latest --context ./context --container-runtime docker
Complete!
We should now have a container image:
docker images | grep awx-ee
cisel/awx-ee latest 94cb5bb21c61 13 minutes ago 701MB
Push this to the registry (here is dockerhub), you will need access to your regitry before (docker login):
docker push cisel/awx-ee:latest
...
Setting Up AWX Environment
On AWX you can now add a custom Execution Environment :
And define the custom image. On our example, we have save our docker image on Dockerhub :
And for the last step, you can configure the Execution Environment on the AWX templates where you need a custom image by selecting the newly created environment :
Feel free to comment this article if you have questions.
Reference: https://www.ansible.com/blog/introduction-to-ansible-builder