Cyber Deals - Get up to 65% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

ansible-builder

ansible-builder

Execution Environment

An execution environment is expected to contain:

  • Ansible
  • Ansible Runner
  • Ansible Collections
  • Python and/or system dependencies of:
    • modules/plugins in collections
    • content in ansible-base
    • custom user needs

Read Migrate legacy venvs to execution environments to learn more.

Install ansible-builder

$ pip install ansible-builder

Refer to the documentation for other methods.

Building custom execution environments with ansible-builder

ansible-builder --help

--tag       name of the container image
--file      specify the config file
--output-filename
            Name of file to write image definition to

Sample execution-environment.yml

---
version: 1
dependencies:
  galaxy: requirements.yml

Sample requirements.yml


collections:

  • name: servicenow.its

Build EE images

```shell
ansible-builder build -v3 -t custom-ee
  • v3 - add verbosity
  • -t custom-ee - tag the image name as custom-ee
  • --container-runtime - specify docker or podman
rhel@ansible project_directory]$ podman images
REPOSITORY                                                               TAG         IMAGE ID      CREATED         SIZE
localhost/custom-ee                                                      latest      8e2411838dd0  15 seconds ago  594 MB
<none>                                                                   <none>      44782f13cb7f  39 seconds ago  602 MB
<none>                                                                   <none>      5b9e207981ac  59 seconds ago  396 MB
registry.redhat.io/ansible-automation-platform-21/ee-supported-rhel8     latest      16674d4e7c5a  3 months ago    1.13 GB
registry.redhat.io/ansible-automation-platform-21/ansible-builder-rhel8  latest      a269ad55a63d  3 months ago    361 MB
registry.redhat.io/ansible-automation-platform-21/ee-minimal-rhel8       latest      9df7b354b3d5  3 months ago    394 MB

execution-environment.yml

---
version: 1
dependencies:
  galaxy: requirements.yml
  python: requirements.txt
  system: bindep.txt
additional_build_steps:
  prepend: |
    RUN whoami
    RUN cat /etc/os-release
  append:
    - RUN echo This is a post-install command!
    - RUN ls -la /etc

requirements.yml

---
collections:
  - name: servicenow.itsm
  - name: ansible.utils

requirements.txt

gcp-cli
ncclient
netaddr
paramiko

bindep.txt

findutils [compile platform:centos-8 platform:rhel-8]
gcc [compile platform:centos-8 platform:rhel-8]
make [compile platform:centos-8 platform:rhel-8]
python38-devel [compile platform:centos-8 platform:rhel-8]
python38-cffi [platform:centos-8 platform:rhel-8]
python38-cryptography [platform:centos-8 platform:rhel-8]
python38-pycparser [platform:centos-8 platform:rhel-8]
ansible-builder build -v3 -t custom-ee

Check podman images

Check context/Containerfile

[rhel@ansible project_directory]$ cat context/Containerfile
ARG EE_BASE_IMAGE=registry.redhat.io/ansible-automation-platform-21/ee-minimal-rhel8:latest
ARG EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-21/ansible-builder-rhel8:latest

FROM $EE_BASE_IMAGE as galaxy
ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS=
USER root

ADD _build /build
WORKDIR /build

RUN ansible-galaxy role install -r requirements.yml --roles-path /usr/share/ansible/roles
RUN ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path /usr/share/ansible/collections

FROM $EE_BUILDER_IMAGE as builder

COPY --from=galaxy /usr/share/ansible /usr/share/ansible

ADD _build/requirements.txt requirements.txt
ADD _build/bindep.txt bindep.txt
RUN ansible-builder introspect --sanitize --user-pip=requirements.txt --user-bindep=bindep.txt --write-bindep=/tmp/src/bindep.txt --write-pip=/tmp/src/requirements.txt
RUN assemble

FROM $EE_BASE_IMAGE
USER root
RUN whoami
RUN cat /etc/os-release

COPY --from=galaxy /usr/share/ansible /usr/share/ansible

COPY --from=builder /output/ /output/
RUN /output/install-from-bindep && rm -rf /output/wheels
RUN echo This is a post-install command!
RUN ls -la /etc

Build an EE for Network Automation

---
version: 1

build_arg_defaults:
  EE_BASE_IMAGE: 'quay.io/ansible/ansible-runner:stable-2.10-devel'
#ARG EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-21/ansible-builder-rhel8:latest

ansible_config: 'ansible.cfg'

dependencies:
  #galaxy: requirements.yml
  python: requirements.txt

Build using Podman

podman build -f Containerfile -t <localimagename>:latest .

Resources

Troubleshooting

Error: writing blob: storing blob to file "/var/tmp/storage404563786/5": gzip: invalid checksum
  • move or delete /var/tmp/storage*
Disclaimer: Views expressed in articles are those of the respective authors and do not necessarily reflect the views of their employers or this site. While we aim for accuracy, please verify information before relying on it, and let us know if you spot an error.
Share:

Related Posts

Ansible Cheatsheet

Ansible Cheatsheet

Ansible Cheat Sheet Ansible is an open-source IT automation engine which can help you to automate most of your repetitive tasks in your work life. …

Ansible for Security

Ansible for Security

Ansible Security Hardening Playbook content RedHatOfficial/ansible-role-rhel7-cis RedHatOfficial/ansible-role-rhel8-cis …

Ansible Automation Platform - Disaster Recovery

Ansible Automation Platform - Disaster Recovery

These are official references to implement Disaster Recovery (DR) designs for Ansible Automation Platform.

Open Source Projects and Products

Open Source Projects and Products

Introduction Open source refers to software where the source code is freely available for anyone to see, modify, and distribute. This fosters …

Ansible Labs

Ansible Labs

Ansible Automation Platform Enable RHEL and AAP Subscriptions Red Hat Container Registry Authentication AAP Download Options Extract the AAP …

Awesome DevSecSysOps Tools on Internet

Awesome DevSecSysOps Tools on Internet

This is a page where I keep all those list of tools on internet, which we use for our day-to-day tasks.