Ansible Builder intro

Ansible Builder is a Python tool used to build execution environments for AAP/AWX. An execution environment is a container acting as the Ansible Controller Node and is a required component in AAP/AWX.

To get started, install Ansible Builder with pip, and make sure you have Podman/Docker installed, as Ansible Builder depends on a containerization tool.

$ pip install ansible-builder

The next thing you need is a file called execution-environment.yml, which Ansible Builder will use to create the Containerfile/Dockerfile and the container context. This file can contain a lot of options, and what you need will depend on the base image you choose and which dependencies your environment requires. You can check out all the  offered by Ansible Builder here.

In this example, the execution environment is built on the latest ee-minimal-rhel8 image. This image contains Python3.9, Ansible Core 2.15, and Ansible Runner 2.4. Remember only to specify dependencies not already listed by the collections you intend to install, as Ansible Builder automatically installs these.

---
version: 3

dependencies:
  galaxy:
    collections:
      - "cisco.nxos"
      - "community.zabbix"

images:
  base_image:
    name: "registry.redhat.io/ansible-automation-platform-25/ee-minimal-rhel8"

options:
  package_manager_path: "/usr/bin/microdnf"

additional_build_steps:
  prepend_base:
    - "RUN pip3 install --upgrade pip setuptools wheel"

You build the image based on the execution-environment.yml file with the ansible-builder build command.

$ ansible-builder build --tag ee --prune-images --verbosity 3

Once the build process has been completed you can play around with the resulting image using Podman/Docker.

$ podman image ls
REPOSITORY                       TAG     IMAGE ID
localhost/ee                     latest  3b82032871d1
$ podman run --user root -it --rm localhost/ee:latest /bin/bash

As you can imagine, building an execution environment is something you’ll need to do often, and I recommend automating the process with Ansible.


Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *