Skip to content

Instantly share code, notes, and snippets.

@CaptainStealthy
Last active August 29, 2024 02:56
Show Gist options
  • Save CaptainStealthy/6c54a5ed3ba66e9d7ee87481e4e178c2 to your computer and use it in GitHub Desktop.
Save CaptainStealthy/6c54a5ed3ba66e9d7ee87481e4e178c2 to your computer and use it in GitHub Desktop.
Ansible/AWX - Building a custom execution environment for Windows server management using ansible-builder v3

TL;DR

Need to build a custom EE for AWX? I needed to do it for managing Windows hosts, but if you need any extra Python modules or Ansible collections, check out the other file snippets.

Build Steps

Environment Setup

Install Python 3 (3.12 is latest as of this writing)

sudo apt update && sudo apt upgrade -y
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3

Create a new Python virtual environment for running Ansible, with the following Python packages installed

  1. Create ~/venv/ansible/requirements.txt (these Python requirements are for the venv only - they aren't to be installed on your custom EE unless you need them for some reason)
autopep8
ansible-core
ansible-builder
ansible-lint
ansible-navigator
flake8
yamllint
pytest
pytest-xdist
  1. Create Python venv and install Ansible tools
python3 -m venv ~/venv/ansible
source ~/venv/ansible/bin/activate
python3 -m pip install -r ~/venv/ansible/requirements.txt

Create a working directory for your custom EE

  • If it's a Git repo, add the context folder to your .gitignore

  • Add the execution-environment.yml, requirements.txt, and requirements.yml files, which are included in this Gist, below this README file.

  • Run the build command and push the image to your favorite cloud-based or self-hosted container registry. That's it!

Build and Push Image to Container Registry

ansible-builder build --tag=your.docker.registry.url/custom-ee:1.0.0 --container-runtime=docker --verbosity=3
# Add extra tags like 'latest', if you want
docker image ls
docker image IMAGEHASH your.docker.registry.url/custom-ee:latest

# Push image to registry
docker push your.docker.registry.url/custom-ee:1.0.0

The Story

I spent hours Googling how to create a custom EE for AWX that would allow me to run community Ansible collections (even just community.general!).

The standard base image when using version 1 (which every blog post you find says to do), for some reason, doesn't have anything newer than 2.13 of ansible-core, and any docs from Red Hat reference a base image that you need to be a RH customer in order to use. And I couldn't get the builder to pull ansible-core >= 2.15 without using version 3 - you can see why I started to pull my hair out.

It was a constant struggle to figure out solutions to the seemingly random Python build errors I was getting, and I ended up FINALLY piecing together a working config from various blog posts, Reddit threads, etc.

Many thanks to u/thenumberfourtytwo on Reddit for the custom EE image that he built, but I wanted to build my own that I could push to my own container registry. And also many thanks to u/MallocArray's comment which gave me a usable base image! The rest of the various links I used for reference are below.

Anyway, I wanted to put this together to help anyone that may stumble across this.

Enjoy!

Other Useful Links

Credits

---
version: 3
images:
base_image:
name: quay.io/centos/centos:stream9
dependencies:
ansible_core:
package_pip: ansible-core>=2.15.8
ansible_runner:
package_pip: ansible-runner
galaxy: requirements.yml
python: requirements.txt
additional_build_steps:
append_base:
- RUN yum upgrade -y
- RUN yum install -y python3
- RUN yum install -y python3-pip
- RUN yum install -y krb5-devel
- RUN yum install -y krb5-libs
- RUN yum install -y krb5-workstation
- RUN yum install -y python3-devel
- RUN yum install -y gcc
- RUN yum install -y epel-release
- RUN python3 -m pip install --upgrade --force pip
- RUN pip3 install pypsrp[kerberos]
- RUN pip3 install pyVim PyVmomi
- COPY --from=quay.io/project-receptor/receptor:latest /usr/bin/receptor /usr/bin/receptor
- RUN mkdir -p /var/run/receptor
dnspython
pykerberos
pywinrm
awxkit==21.6.0
urllib3
collections:
- name: ansible.netcommon
- name: ansible.utils
- name: ansible.windows
- name: community.crypto
- name: community.dns
- name: community.docker
- name: community.general
- name: community.grafana
- name: community.network
- name: community.windows
- name: microsoft.ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment