Build a Custom Ansible Execution Environment - ansible-builder command-line tool
How to build custom “my_ee” Ansible Execution Environment specifying some custom System (git), Python (boto), and collection (community.aws) dependencies using the ansible-builder command-line tool.
How to build a custom Ansible Execution Environment?
Using an Ansible Execution Environment is the latest technology to maintain up-to-date Python dependency of the Ansible collections without interfering with your Linux system. It’s the evolution of Python Virtual Environment. This initial configuration sometimes is a roadblock for some Ansible users. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible Execution Environment
- Ansible Execution Environment
Let’s talk about the Ansible Execution Environment.
The Ansible Execution Environment is container images that can be utilized as Ansible control nodes.
It’s the latest technology developed by Red Hat to simplify the automation process.
The main advantage is a standard environment for Development and Production images using container technology creating portable automation runtimes.
This technology superseded manual Python Virtual Environments, Ansible module dependencies, and bubblewrap.
Experienced users are probably familiar with a lot of challenges managing custom Python Virtual Environments and Ansible module dependencies. Enterprise users of Ansible Automation Platform were familiar with limiting execution jobs under bubblewrap in order to isolate processes
The creation is performed by the Ansible Builder tool.
Ansible Builder produces a directory that acts as the build context for the container image build, containing the
Containerfile, along with any other files that need to be added to the image.
On the other end, the execution is performed by the Ansible Runner tool.
The Ansible Runner enables you to run the Execution Environment as a container in the current machine. It is basically taking care that the content runs as expected.
The Best Resources For Ansible
- Learn Ansible Automation in 250+examples & practical lessons: Learn Ansible with some real-life examples of how to use the most common modules and Ansible Playbook
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
Build an Ansible Execution Environment using ansible-builder tool
- Execution Environment name: my_ee
- System dependency: git
- Python dependency boto3
- Collection dependency: community.aws
How to Build an Ansible Execution Environment using ansible-builder tool.
I’m going to show you how to Build a custom “my_ee” Ansible Execution Environment using the ansible-builder tool specifying some custom System, Python, and collection dependency.
For example, let’s build a custom Ansible Execution Environment named “my_ee” With System requirements
git, Python libraries
boto3 and Amazon Collection
--- version: 1 dependencies: galaxy: requirements.yml python: requirements.txt system: bindep.txt additional_build_steps: prepend: | RUN pip3 install --upgrade pip setuptools append: - RUN ls -al /
--- collections: - name: community.aws
botocore>=1.18.0 boto3>=1.15.0 boto>=2.49.0
git [platform:rpm] git [platform:dpkg]
$ ansible-builder build -t my_ee -v 3 Running command: podman build -f context/Containerfile -t my_ee context Complete! The build context can be found at: /home/devops/ee/context
When the ansible-builder tool is not installed you should install it via DNF command using the ansible Automation Platform subscription:
[[email protected] ee]# dnf install ansible-builder
The tool needs access to the Red Hat Container Registry available with your Red Hat Ansible Automation subscription (username and password of Red Hat Portal).
$ podman login registry.redhat.io
A successful build produces the following context/Containerfile:
ARG EE_BASE_IMAGE=registry.redhat.io/ansible-automation-platform-22/ee-minimal-rhel8:latest ARG EE_BUILDER_IMAGE=registry.redhat.io/ansible-automation-platform-22/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_DISABLE_GPG_VERIFY=1 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 pip3 install --upgrade pip setuptools COPY --from=galaxy /usr/share/ansible /usr/share/ansible COPY --from=builder /output/ /output/ RUN /output/install-from-bindep && rm -rf /output/wheels RUN ls -la /
Now you know how to Build an Ansible Execution Environment using the
ansible-builder command-line tool with custom System, Python and Ansible collection.
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and aws System Administrator and DevOps
Want to keep this project going? Please donate