# Create a custom awx-ee docker 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:

```plaintext
#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:

```plaintext
pip install wheel --upgrade
pip install ansible --upgrade
pip3 install ansible-builder==3.0.0
```

Create the config execution-environment.yml :

```plaintext
---
version: 3
images:
  base_image:
    name: quay.io/centos/centos:stream9
    
dependencies:
  galaxy: |
    ---
    collections:
      - community.windows
      - community.general
      - ansible.windows
      - community.aws
      - amazon.aws
      - ansible.netcommon
      - ansible.posix
      - kubernetes.core
  python: |
    git+https://github.com/ansible/ansible-sign
    git+https://github.com/ansible/ansible-builder.git@devel#egg=ansible-builder
    urllib3
    jmespath
    kubernetes

  system: |
    python3.9-devel [platform:rpm compile]
    subversion [platform:rpm]
    subversion [platform:dpkg]
    git-lfs [platform:rpm]
    net-tools [platform:rpm]
    lftp [platform:rpm]
    jq [platform:rpm]
    unzip [platform:rpm]
    azure-cli [platform:rpm]

  # python38-devel [platform:rpm compile]
  ansible_core:
    package_pip: ansible-core
  ansible_runner:
    package_pip: ansible-runner

additional_build_steps:
  append_base:
    - RUN $PYCMD -m pip install -U pip
    - RUN /usr/bin/python3 -m pip install --upgrade pip
    - RUN rpm --import https://packages.microsoft.com/keys/microsoft.asc
    - RUN dnf install -y https://packages.microsoft.com/config/rhel/9.0/packages-microsoft-prod.rpm
  append_final:
    - RUN curl -LO "https://github.com/Azure/kubelogin/releases/download/v0.1.0/kubelogin-linux-amd64.zip"
    - RUN unzip kubelogin-linux-amd64.zip
    - RUN mv ./bin/linux_amd64/kubelogin /usr/local/bin/kubelogin
    - RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
    - RUN chmod +x ./kubectl
    - RUN mv ./kubectl /usr/local/bin
    - RUN curl -LO "https://get.helm.sh/helm-v3.14.0-linux-amd64.tar.gz"
    - RUN tar -zxvf helm-v3.14.0-linux-amd64.tar.gz
    - RUN mv ./linux-amd64/helm /usr/local/bin/helm
    - COPY --from=quay.io/ansible/receptor:devel /usr/bin/receptor /usr/bin/receptor
    - RUN az upgrade
    - RUN mkdir -p /var/run/receptor
    - RUN git lfs install --system
```

Build the EE Image

```plaintext
ansible-builder build --tag cisel/awx-ee:latest --context ./context --container-runtime docker
```

Complete!

We should now have a container image:

```plaintext
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):

```plaintext
docker push cisel/awx-ee:latest
...
```

## Setting Up AWX Environment

On AWX you can now add a custom Execution Environment :

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637076483859/oVOgqj8OP.png align="left")

And define the custom image. On our example, we have save our docker image on Dockerhub :

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637076582687/6jGpR_usZ.png align="left")

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 :

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1637076775323/a7H-KGsjo.png align="left")

Feel free to comment this article if you have questions.

cisel.ch

Reference: [https://www.ansible.com/blog/introduction-to-ansible-builder](Link)
