Ansible-Builder Documentation: Release Unversioned
Ansible-Builder Documentation: Release Unversioned
Release unversioned
i
6.9 Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.10 Copying arbitrary files to EE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.11 Building EEs with environment variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
6.12 Building EEs with environment variables for Galaxy configuration . . . . . . . . . . . . . . . . . . . 40
6.13 Passing Secrets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
6.14 Validating Installed Python Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Index 43
ii
ansible-builder Documentation, Release unversioned
With ansible-builder you can configure and build portable, consistent, customized Ansible control nodes that are
packaged as containers by Podman or Docker. These containers are known as execution environments. You can use
them on AWX or Ansible Controller, with Ansible Navigator, for local playbook development and testing, in your CI
pipelines, and anywhere else you run automation.
You can design and distribute specialized execution environments for your Ansible content, choosing the versions of
Python and ansible-core you want, and installing only the Python packages, system packages, and Ansible collections
you need for your tasks.
ò Note
Need help or want to discuss Ansible Builder including the documentation? See the Community guide to learn how
to join the conversation!
CONTENTS: 1
ansible-builder Documentation, Release unversioned
2 CONTENTS:
CHAPTER
ONE
Ansible Builder depends on more generalized containerization tools like Podman or Docker.
Before you start using Ansible Builder, you should understand the following concepts and terms relevant to any use of
containers:
• Build instruction file (called a Containerfile in Podman and a Dockerfile in Docker): an instruction file
for creating a container image by installing and configuring the code and dependencies.
• Container: a package of code and dependencies that runs a service or an application across a variety of com-
puting environments.
• Image: a complete but inactive version of a container - you can distribute images and create one or more con-
tainers based on each image.
3
ansible-builder Documentation, Release unversioned
TWO
Refer to the Getting started with Execution Environments guide for details.
5
ansible-builder Documentation, Release unversioned
THREE
To get started with Ansible Builder, you must install the ansible-builder utility and a containerization tool.
Once you have the tools you need, create an execution environment definition file. By default, this file is called
[Link] (the .yaml extension is also accepted). In the execution environment definition file,
you can specify the exact content you want to include in your execution environment. You can specify these items:
• the base container image
• the version of Python
• the version of ansible-core
• the version of ansible-runner
• Ansible collections, with version restrictions
• system packages, with version restrictions
• Python packages, with version restrictions
• other items to download, install, or configure
7
ansible-builder Documentation, Release unversioned
FOUR
Ansible Builder requires RPM-based container images that use the dnf or microdnf package manager. Non-RPM-
based distributions (such as Debian, Ubuntu, or Alpine) are not supported and will fail to build.
Ansible Builder’s default configuration and internal tooling assume the use of dnf package management, which is
present on RPM-based Linux distributions. The following are examples of images that should work with Ansible
Builder:
• CentOS Stream: [Link]/centos/centos:stream9
• Rocky Linux: [Link]/rockylinux/rockylinux:9
• Fedora: [Link]/fedora:43
• Red Hat Universal Base Image (UBI): [Link]/ubi9/ubi:latest
• RHEL-based Ansible Automation Platform images: [Link]/
ansible-automation-platform-*/ee-*
The examples above demonstrate compatible images, but any RPM-based image with dnf or microdnf should work.
When choosing a base image, prefer smaller images when possible, as they result in smaller final execution environment
images. However, ensure you understand what packages are already installed on the base image to avoid redundant
installations. For example, some base images already have Python installed, while others do not.
9
ansible-builder Documentation, Release unversioned
FIVE
11
ansible-builder Documentation, Release unversioned
SIX
When Ansible Builder installs collections into an execution environment, it also installs each collection’s dependencies
if they are specified. Collection maintainers can learn to correctly declare dependencies for their collections from the
collection-level dependencies page.
6.1 Community
We welcome your feedback, questions and ideas. Here’s how to reach the community.
6.2 Installation
• Requirements
• Base Image Requirements
• Install from PyPI
• Install from Source
13
ansible-builder Documentation, Release unversioned
6.2.1 Requirements
• To build images, you must install a containerization tool - either podman or docker - as well as the
ansible-builder Python package.
• The --container-runtime option must correspond to the containerization tool you use.
• ansible-builder version 3.x requires Python 3.9 or higher.
ò Note
To install from a specific tag or branch, replace <ref> in the following example:
ò Note
This page documents the definition schema for Ansible Builder 3.x. If you are running an older version of Ansible
Builder, you need an older schema version. Please consult older versions of the docs for more information. We
recommend using version 3, which is more configurable and functional than previous versions.
• Overview
• Version 3 sample files
• Configuration options
– additional_build_files
– additional_build_steps
– build_arg_defaults
– dependencies
– images
∗ image verification
– options
– version
6.3.1 Overview
The Ansible Builder 3.x execution environment definition file accepts seven top-level sections:
• additional_build_files
• additional_build_steps
• build_arg_defaults
• dependencies
• images
• options
• version
---
version: 3
images:
base_image:
name: [Link]/redhat/ubi9:latest
dependencies:
ansible_core:
package_pip: ansible-core
ansible_runner:
package_pip: ansible-runner
The second example below is more detailed and is not usable without modification and/or the creation of supporting
requirements and extra files, but does demonstrate more complete EE file syntax.
---
version: 3
build_arg_defaults:
ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: '--pre'
dependencies:
ansible_core:
package_pip: ansible-core==2.14.4
ansible_runner:
package_pip: ansible-runner
galaxy: [Link]
python:
- six
- psutil
system: [Link]
exclude:
python:
- docker
system:
- python3-Cython
images:
base_image:
name: [Link]/redhat/ubi9:latest
# NOTE: Ansible Builder requires RPM-based images (those using dnf package␣
˓→management).
additional_build_files:
- src: files/[Link]
dest: configs
additional_build_steps:
prepend_base:
- RUN echo This is a prepend base command!
# Enable Non-default stream before packages provided by it can be installed.␣
˓→(optional)
additional_build_files
Specifies files to be added to the build context directory. These can then be referenced or copied by addi-
tional_build_steps during any build stage. The format is a list of dictionary values, each with a src and dest key
and value.
Each list item must be a dictionary containing the following (non-optional) keys:
src
Specifies the source file(s) to copy into the build context directory. This may either be an absolute
path (e.g., /home/user/.[Link]), or a path that is relative to the execution environment file.
Relative paths may be a glob expression matching one or more files (e.g. files/*.cfg). Note that
an absolute path may not include a regular expression. If src is a directory, the entire contents of
that directory are copied to dest.
dest
Specifies a subdirectory path underneath the _build subdirectory of the build context directory that
should contain the source file(s) (e.g., files/configs). This may not be an absolute path or contain
.. within the path. This directory will be created for you if it does not exist.
additional_build_steps
Specifies custom build commands for any build phase. These commands will be inserted directly into the build in-
struction file for the container runtime (e.g., Containerfile or Dockerfile). The commands must conform to any rules
required by the containerization tool.
You can add build steps before or after any stage of the image creation process. For example, if you need git to be
installed before you install your dependencies, you can add a build step at the end of the base build stage.
Below are the valid keys for this section. Each supports either a multi-line string, or a list of strings.
prepend_base
Commands to insert before building of the base image.
append_base
Commands to insert after building of the base image.
prepend_galaxy
Commands to insert before building of the galaxy image.
append_galaxy
Commands to insert after building of the galaxy image.
prepend_builder
Commands to insert before building of the builder image.
append_builder
Commands to insert after building of the builder image.
prepend_final
Commands to insert before building of the final image.
append_final
Commands to insert after building of the final image.
ò Note
Please make sure that you do not specify USER directives in these build steps. This may lead to failures while
building the image. If you want to override the USER setting, consider using the [Link] setting mentioned
below.
build_arg_defaults
Specifies default values for build args as a dictionary. This is an alternative to using the --build-arg CLI flag.
Build args used by ansible-builder are the following:
ANSIBLE_GALAXY_CLI_COLLECTION_OPTS
This allows the user to pass the –pre flag (or others) to enable the installation of pre-release collec-
tions.
ANSIBLE_GALAXY_CLI_ROLE_OPTS
This allows the user to pass any flags, such as –no-deps, to the role installation.
PKGMGR_PRESERVE_CACHE
This controls how often the package manager cache is cleared during the image build process. If
this value is not set, which is the default, the cache is cleared frequently. If it is set to the string
always, the cache is never cleared. Any other value forces the cache to be cleared only after the
system dependencies are installed in the final build stage.
Ansible Builder hard-codes values given inside of build_arg_defaults into the build instruction file, so they will
persist if you run your container build manually.
If you specify the same variable in the execution environment definition and at the command line with the CLI --build-
arg flag, the CLI value will take higher precedence (the CLI value will override the value in the execution environment
definition).
dependencies
Specifies dependencies to install into the final image, including ansible-core, ansible-runner, Python packages,
system packages, and Ansible Collections. Ansible Builder automatically installs dependencies for any Ansible Col-
lections you install.
In general, you can use standard syntax to constrain package versions. Use the same syntax you would pass to dnf,
pip, ansible-galaxy, or any other package management utility. You can also define your packages or collections in
separate files and reference those files in the dependencies section of your execution environment definition file.
The following keys are valid for this section:
ansible_core
The version of the ansible-core Python package to be installed. This value is a dictionary with a
single key, package_pip. The package_pip value is passed directly to pip for installation and can
be in any format that pip supports. Below are some example values:
ansible_core:
package_pip: ansible-core
ansible_core:
(continues on next page)
ansible_runner
The version of the Ansible Runner Python package to be installed. This value is a dictionary with a
single key, package_pip. The package_pip value is passed directly to pip for installation and can
be in any format that pip supports. Below are some example values:
ansible_runner:
package_pip: ansible-runner
ansible_runner:
package_pip: ansible-runner==2.3.2
ansible_runner:
package_pip: [Link]
˓→refs/heads/[Link]
galaxy
Ansible Collections to be installed from Galaxy. This may be a filename, a dictionary, or a multi-line
string representation of an Ansible Galaxy [Link] file (see below for examples). Read
more about the requirements file format in the Galaxy user guide.
python
The Python installation requirements. This may either be a filename, or a list of requirements (see
below for an example).
ò Note
Python requirement specifications are expected to be limited to features defined by PEP 508.
Hash tag comments will always be allowed. Any deviation from this specification will be passed
through to pip unverified and unaltered, although this is considered undefined and unsupported
behavior. It is not recommended that you depend on this behavior.
python_interpreter
A dictionary that defines the Python system package name to be installed by dnf (package_system)
and/or a path to the Python interpreter to be used (python_path).
system
The system packages to be installed, in bindep format. This may either be a filename, or a list of
requirements (see below for an example).
exclude
A dictionary defining the Python or system requirements to be excluded from the top-level depen-
dency requirements of referenced collections. These exclusions will not apply to the user supplied
Python or system dependencies, nor will they apply to dependencies of dependencies (top-level only).
The following keys are valid for this section:
• python - A list of Python dependencies to be excluded.
• system - A list of system dependencies to be excluded.
• all_from_collections - If you want to exclude all Python and system dependencies from
one or more collections, supply a list of collection names under this key.
ò Note
The regular expression must match the full requirement/collection name. For example, ~foo.
does not fully match the name foobar, but ~foo.+ does.
With both forms of matching, the exclusion string will be compared against the simple name of any
Python or system requirement. For example, if you need to exclude the system requirement that
appears as foo [!platform:gentoo] within an included collection, then your exclusion string
should be foo. To exclude the Python requirement bar == 1.0.0, your exclusion string would be
bar.
Example using both simple and advanced matching:
dependencies:
exclude:
python:
- docker
system:
- python3-Cython
all_from_collections:
# Regular expression to exclude all from community collections
- ~community\..+
ò Note
dependencies:
python: [Link]
system: [Link]
galaxy: [Link]
ansible_core:
package_pip: ansible-core==2.14.2
ansible_runner:
package_pip: ansible-runner==2.3.1
python_interpreter:
package_system: "python310"
python_path: "/usr/bin/python3.10"
dependencies:
python:
- pywinrm
system:
- iputils [platform:rpm]
galaxy:
collections:
- name: [Link]
- name: [Link]
version: 2.10.1
ansible_core:
package_pip: ansible-core==2.14.2
ansible_runner:
package_pip: ansible-runner==2.3.1
python_interpreter:
package_system: "python310"
python_path: "/usr/bin/python3.10"
images
Specifies the base image to be used. At a minimum you MUST specify a source, image, and tag for the base image. The
base image provides the operating system and may also provide some packages. We recommend using the standard
host/namespace/container:tag syntax to specify images. You may use Podman or Docker shortcut syntax instead,
but the full definition is more reliable and portable.
Valid keys for this section are:
base_image
A dictionary defining the parent image for the execution environment. A name key must be supplied
with the container image to use. Use the signature_original_name key if the image is mirrored
within your repository, but signed with the original image’s signature key.
image verification
You can verify signed container images if you are using the podman container runtime. Set the --container-policy CLI
option to control how this data is used with a Podman [Link] file for container image signature validation.
• ignore_all policy: Generate a [Link] file in the build context directory where no signature validation is
performed.
• system policy: Signature validation is performed using pre-existing [Link] files in standard system loca-
tions. ansible-builder assumes no responsibility for the content within these files, and the user has complete
control over the content.
• signature_required policy: ansible-builder will use the container image definitions here to generate a
[Link] file in the build context directory that will be used during the build to validate the images.
options
A dictionary of keywords/options that can affect builder runtime functionality. Valid keys for this section are:
container_init
A dictionary with keys that allow for customization of the container ENTRYPOINT and CMD directives
(and related behaviors). Customizing these behaviors is an advanced task, and may result in sub-
tle, difficult-to-debug failures. As the provided defaults for this section control several intertwined
behaviors, overriding any value will skip all remaining defaults in this dictionary. Valid keys are:
cmd
Literal value for the CMD Containerfile directive. The default value is ["bash"].
entrypoint
Literal value for the ENTRYPOINT Containerfile directive. The default entrypoint behavior han-
dles signal propagation to subprocesses, as well as attempting to ensure at runtime that the con-
tainer user has a proper environment with a valid writeable home directory, represented in /etc/
passwd, with the HOME envvar set to match. The default entrypoint script may emit warnings to
stderr in cases where it is unable to suitably adjust the user runtime environment. This behav-
ior can be ignored or elevated to a fatal error; consult the source for the entrypoint target script
for more details. The default value is ["/opt/builder/bin/entrypoint", "dumb-init"].
package_pip
Package to install via pip for entrypoint support. This package will be installed in the final build
image. The default value is dumb-init==1.2.5.
package_manager_path
A string with the path to the package manager to use. The default is /usr/bin/dnf.
This option allows you to choose between different RPM package managers available on your base
image, such as /usr/bin/dnf or /usr/bin/microdnf. The package manager is used to install
system packages, and if specified in dependencies, to install a Python interpreter during the build
phase.
. Warning
Only RPM-based package managers (for example, dnf or microdnf) are supported. Non-RPM
package managers such as apt-get (Debian/Ubuntu) or apk (Alpine) are not supported and will
cause build failures.
skip_ansible_check
This boolean value controls whether or not the check for an installation of Ansible and Ansible
Runner is performed on the final image. Set this value to True to not perform this check. The default
is False.
skip_pip_install
This boolean value controls whether or not we attempt to install pip into the base image. Pip is
necessary for Python requirement installation, among other things. You may choose to disable this
step and handle installing pip manually if the current method of pip installation does not work for
you. The default is False.
relax_passwd_permissions
This boolean value controls whether the root group (GID 0) is explicitly granted write permission
to /etc/passwd in the final container image. The default entrypoint script may attempt to update
/etc/passwd under some container runtimes with dynamically created users to ensure a fully func-
tional POSIX user environment and home directory. Disabling this capability can cause failures of
software features that require users to be listed in /etc/passwd with a valid and writeable home
directory (eg, async in ansible-core, and the ~username shell expansion). The default is True.
workdir
Default current working directory for new processes started under the final container image. Some
container runtimes also use this value as HOME for dynamically-created users in the root (GID 0)
group. When this value is specified, the directory will be created (if it doesn’t already exist), set to
root group ownership, and rwx group permissions recursively applied to it. The default value is
/runner.
user
This sets the username or UID to use as the default user for the final container image. The default
value 1000.
tags
Specifies the names that are assigned to the resulting image if the build process completes success-
fully. The default value is ansible-execution-env:latest.
Example options section:
options:
container_init:
package_pip: dumb-init>=1.2.5
entrypoint: '["dumb-init"]'
cmd: '["csh"]'
package_manager_path: /usr/bin/microdnf
relax_passwd_permissions: false
skip_ansible_check: true
workdir: /myworkdir
user: bob
tags:
- ee_development:latest
version
An integer value that sets the schema version of the execution environment definition file. Defaults to 1. Must be 3 if
you are using Ansible Builder 3.x.
ò Note
Ansible Builder is colorized by default when outputting to a terminal. Color output can be disabled by setting the
NO_COLOR environment variable to any non-empty value, or by setting the CLICOLOR environment variable to 0.
– --galaxy-keyring
– --galaxy-ignore-signature-status-code
– --galaxy-required-valid-signature-count
– --context
– --build-arg
– --container-runtime
– --container-policy
– --container-keyring
– --extra-build-cli-args
– --verbosity
– --prune-images
– --squash
• The create command
• The introspect command
• Flags for the introspect command
– folder
– --write-pip
– --write-bindep
– --user-pip
– --user-bindep
– --exclude-pip-reqs
– --exclude-bindep-reqs
– --exclude-collection-reqs
• Examples
• Deprecated Features
$ ansible-builder build
Running command:
podman build -f context/Containerfile -t ansible-execution-env:latest context
Complete! The build context can be found at: /path/to/context
Ansible Builder produces a ready-to-use container image and preserves the build context, which you can use to rebuild
the image at a different time and/or location with the tooling of your choice.
--file
Specifies the execution environment file. To use a file other than the default:
--galaxy-keyring
Specifies a keyring for ansible-galaxy to use to verify collection signatures during installation. To verify collection
signatures:
If you do not pass this option, no signature verification is performed. If you do pass this option, but the version of
Ansible is too old to support this feature, you will see an error during the image build process.
--galaxy-ignore-signature-status-code
Ignores certain errors that may occur while verifying collections. This option is passed unmodified to ansible-galaxy
calls. Valid only when --galaxy-keyring is also set. See the ansible-galaxy documentation for more information.
--galaxy-required-valid-signature-count
Overrides the number of required valid collection signatures. This option is passed unmodified to ansible-galaxy
calls. Valid only when --galaxy-keyring is also set. See the ansible-galaxy documentation for more information.
--context
Specifies the directory name for the build context Ansible Builder creates. Default directory name is context in the
current working directory. To specify another location:
--build-arg
Passes build-time arguments to Podman or Docker. Specify these flags or variables the same way you would with
podman build or docker build.
By default, the Containerfile / Dockerfile created by Ansible Builder contains a build argument EE_BASE_IMAGE, which
can be useful for rebuilding execution environments without modifying any files.
To use different build arguments, you can specify --build-arg multiple times:
--container-runtime
Specifies the containerization tool used to build images. Default is Podman. To use Docker:
--container-policy
ò Note
Specifies the container image validation policy to use. Valid only when --container-runtime is podman. Valid values
are one of:
• ignore_all: Run podman with generated policy that ignores all signatures.
• system: Relies on podman’s consumption of system policy/signature with inline keyring paths. No builder-
specific overrides are possible.
• signature_required: Run podman with --pull-always and a generated
policy that rejects all by default, with generated identity requirements for referenced container images, using
an explicitly-provided keyring (specified with the --container-keyring CLI option).
--container-keyring
ò Note
Specifies the path to a GPG keyring file to use for validating container image signatures.
--extra-build-cli-args
ò Note
This option allows the user to pass any additional command line arguments to the container engine build command
(docker build or podman build). Take care when using this option as there is no attempt to identify or resolve
conflicting argument values from this option and arguments normally added by ansible-builder.
--verbosity
Customizes the level of verbosity:
You may also use -v for the shorthand version. You may either specify an integer for the verbosity level, or supply
multiples of the option. Individual instances of -v will stack. For example, the following are equivalent to setting the
verbosity level to 3:
$ ansible-builder build -v 3
$ ansible-builder build -vvv
$ ansible-builder build -v -v -v
--prune-images
Removes unused images created after the build process:
ò Note
This flag removes all the dangling images on the given machine whether they already existed or were created by
ansible-builder build process.
--squash
Controls the final image layer squashing. Valid values are:
• new: Squash all of the final image’s new layers into a single new layer (preexisting layers are not squashed).
• all: Squash all of the final image’s layers, including those inherited from the base image, into a single new layer.
ò Note
This flag is compatible only with the podman runtime and will be ignored for any other runtime. Docker does not
support layer squashing; it is considered an experimental feature.
$ ansible-builder introspect
--write-pip
Write the combined pip requirements to a file. This option outputs all Python dependencies found across the intro-
spected collections to the specified file.
--write-bindep
Write the combined bindep requirements to a file. This option outputs all system-level dependencies found across the
introspected collections to the specified file.
--user-pip
Specify an additional pip requirements file to combine with collection requirements. This is useful when you have
custom Python dependencies that should be included alongside the collection dependencies.
--user-bindep
Specify an additional bindep requirements file to combine with collection requirements. This is useful when you have
custom system-level dependencies that should be included alongside the collection dependencies.
--exclude-pip-reqs
Exclude specific pip requirements listed in a file. Each line in the file should contain one Python package name to
exclude from the final output.
--exclude-bindep-reqs
Exclude specific bindep requirements listed in a file. Each line in the file should contain one system package name to
exclude from the final output.
--exclude-collection-reqs
Exclude all requirements from specific collections listed in a file. Each line in the file should contain one collection
name (in the format [Link]) whose requirements should be excluded from the final output.
ò Note
The introspect command also supports the --verbosity flag, which works the same way as described in the
build command documentation above.
6.4.6 Examples
The example in test/data/pytz requires the [Link] collection in the execution environment definition. The
lookup plugin [Link].schedule_rrule requires the PyPI pytz and another library to work. If test/data/
pytz/[Link] file is given to the ansible-builder build command, then it will install
the collection inside the image, read [Link] inside of the collection, and then install pytz into the image.
The image produced can be used inside of an ansible-runner project by placing these variables inside the env/
settings file, inside of the private data directory.
---
container_image: image-name
process_isolation_executable: podman # or docker
process_isolation: true
The [Link] collection is a subset of content included in the default AWX execution environment. More details can
be found at the awx-ee repository.
ò Note
If present, the files below must be included in the packaged collection on Galaxy. Ansible Builder cannot install
dependencies listed in files that are included in the build_ignore of a collection, because those files are not
included in the collection artifact.
If you are a collection maintainer, make sure the controller-side dependencies are specified and verified.
We recommend you specify paths to dependency files in the meta/[Link] file. Here is an
example of its content:
dependencies:
python: meta/[Link] # List Python package requirements in the file
system: meta/[Link] # List system package requirements in the file
If the meta/[Link] file is not present, by default, Ansible Builder will expect the dependen-
cies to be defined in:
• the [Link] file in the collection root directory for Python package requirements
• the [Link] file in the collection root directory for system package requirements
ò Note
If your collection uses the [Link] or [Link] files in its root directory for anything else but
its controller-side dependencies, for example, for listing testing requirements, make sure you use the meta/
[Link] file to specify other dependency files for execution environment purposes.
A user can see the introspection output during the builder intermediate phase using the build -v3 option.
ò Note
Running the introspect command described below is not part of a typical workflow for building and using execution
environments.
Collection developers can verify that dependencies specified in the collection will be processed correctly by Ansible
Builder.
To do that, the collection has to be installed locally.
The default collection path used by the ansible-galaxy command is ~/.ansible/collections/. Read more
about collection paths in the Ansible configuration settings guide.
ò Note
Use the -v3 option to introspect to see logging messages about requirements that are being excluded.
ansible_collections/NAMESPACE/COLLECTION
For example, if you need to inspect the [Link] collection, the path will be:
ansible_collections/community/docker
Then, if the ansible_collection directory is in your home directory, you can run introspect with the following
command:
ansible-builder introspect ~/
Python Dependencies
Ansible Builder combines all the Python requirements files from all collections into a single file.
Certain package names are specifically ignored by ansible-builder, meaning that Ansible Builder does not include
them in the combined file of Python dependencies, even if a collection lists them as dependencies. These include test
packages and packages that provide Ansible itself. The full list can be found in EXCLUDE_REQUIREMENTS in src/
ansible_builder/_target_scripts/[Link].
If you need to include one of these ignored package names, use the --user-pip option of the introspect command
to list it in the user requirements file. Packages supplied this way are not processed against the list of excluded Python
packages.
ò Note
These dependencies are subject to the same PEP 508 format restrictions described for Python requirements in the
EE definition specification.
System-level Dependencies
For system packages, use the bindep format to specify cross-platform requirements, so they can be installed by
whichever package management system the execution environment uses. Collections should specify necessary re-
quirements for [platform:rpm].
Ansible Builder combines system package entries from multiple collections into a single file.
• Requirements with compile profile indicate that these requirements are needed to install other requirements
(especially Python ones), but are not required to be in the final build.
• Requirements with epel profile indicate that EPEL repositories will be enabled before installing these require-
ments.
• Only requirements with no profiles (runtime requirements) are installed to the image.
Entries from multiple collections which are outright duplicates of each other may be consolidated in the combined file.
New Features
Disabling Colorized Output
Colorized terminal output can be disabled by either setting the NO_COLOR environment variable to any non-empty value,
or by setting the CLICOLOR environment variable to 0.
Behavior Changes
Preserve Symlinks During Additional Build File Copies
When using symlinks in the additional_build_files section of an EE, previous behavior was to dereference the
symlink to copy the actual file into the container build context. If the symlink pointed to a file that didn’t exist, this
would result in an error. The new behavior is to copy the symlink itself. See this issue for more information.
This release adds improved error detection and reporting for invalid [Link] files. Previously, when bindep
encountered unparsable content in a [Link] file, the build would continue and potentially fail later with unclear
error messages. Now, the build will fail immediately with a clear error message when bindep reports a parse error.
When the bindep program exits with code 2 (indicating unparsable content in [Link]), the build process will
now:
1. Stop immediately at the point where the parse error is detected
2. Output a clear error message: Error: [Link] contains unparsable content
3. Exit with code 2
This change affects the assemble script that runs during the builder phase of execution environment creation.
ò Note
This behavior change requires your container image have bindep version 2.14.0 or higher installed. Versions below
this will not halt execution on unparsable content.
Deprecations
Execution environment schema versions 1 and 2 are deprecated and scheduled to be removed from Ansible Builder 3.3.
If you are currently using one of these versions, you will need to update your [Link] files to
the version 3 format.
A warning about the deprecation is sent to the logging output of the create or build commands when an execution
environment definition file is found to be using one of the deprecated versions.
ò Note
We highly advise running ansible-builder with increased verbosity using the -vvv option (--v3 for versions
older than 3.1) to fully expose any error messages that may help in diagnosing any problems.
Topics
Python requirements files are expected to follow the PEP 508 standard. Builder will expect the requirements file to be
in this format, but it makes two exceptions:
1. Comments (lines beginning with #) are ignored.
2. Any line from the requirements file that is not compliant with PEP508 causes a warning to be emitted and the line
passed through to pip unmodified. It is not recommended to depend on this behavior, as it can change suddenly
between pip releases, and can cause other problems with dependency resolution.
The passthrough of non-PEP508 compliant lines may expose issues that were hidden by the version 3.0 dependency
sanitizer, which often silently ignored and removed them.
Dependency Sanitization
Dependency sanitization (the combining of duplicate dependencies into a single dependency entry) is no longer per-
formed by ansible-builder.
ò Note
The --sanitize option to the ansible-builder introspect command still exists, but is now undocumented
and does nothing.
The effect of this change is that builder will now pass a listed dependency multiple times for each requirement file in
which it is found. For example, with version 3.0, if collection A listed the Python dependency foo, and collection B
listed the dependency foo>=1.0, then it would have appeared in the combined Python requirements file as a single
entry:
Now, with version 3.1, those dependencies are no longer combined and will appear in the combined Python require-
ments file as separate entries:
If your container image has an older version of pip, this change might cause an error during the image build process.
This guide covers how to deal with this situation below.
Common Issues
This section lists some common errors that might be encountered when running ansible-builder version 3.1.
Because dependency sanitization has been removed, all Python requirements from included collections and user re-
quirement files are passed along to the pip command that installs those requirements. Due to this change, the image
build may exit abnormally with an error similar to the following:
˓→'netaddr')
This error comes from pip within one of the intermediate container images when attempting to install the Python
requirements from included collections and/or from the user supplied requirements. This intermediate image is based
on the base image defined within the Execution Environment file, and it means that the version of pip installed within
that image is too old to handle duplicate requirement entries.
To determine where the duplicate requirements are coming from, run ansible-builder with the -vvv option to get
more verbose output, then look for the output from the introspection phase. It will look similar to:
In the example output above, the double Python requirement for netaddr is coming from the collections ansible.
netcommon and [Link].
The solution requires upgrading pip within the base image to a version that contains an updated dependency resolver.
Beginning with pip version 20.3, the dependency resolver can handle duplicate requirements whose versions do not
conflict, so that version is the minimum required. Upgrade pip in the base image from within the Execution Environ-
ment file by adding these lines to it:
additional_build_steps:
append_base:
- RUN $PYCMD -m pip install -U pip
That will upgrade pip to the latest version within the base image. To restrict the upgrade to a specific version of pip,
alter the upgrade command to specify that version. For example:
additional_build_steps:
append_base:
- RUN $PYCMD -m pip install -U pip==20.3
Topics
· image verification
∗ options
∗ version
Overview
The Ansible Builder 3.x execution environment definition file accepts seven top-level sections:
• additional_build_files
• additional_build_steps
• build_arg_defaults
• dependencies
• images
• options
• version
Porting options
You need to change the configuration YAML keys in your older (v1 and v2) execution environment file to the one listed
here.
additional_build_files
This is a new configuration that can be used to specify files to be added to the build context directory. These can then
be referenced or copied by additional_build_steps during any build stage.
See the additional_build_files section for more details.
additional_build_steps
With Ansible Builder 3, you can specify more fine-grained build steps or custom commands for any build phase. These
commands will be inserted directly into the build instruction file for the container runtime (For example, Containerfile
or Dockerfile). The commands must conform to any rules required by the containerization tool.
These are additional build steps -
• prepend_base
• append_base
• prepend_galaxy
• append_galaxy
• prepend_builder
• append_builder
• prepend_final
• append_final
See the additional_build_steps section for more details.
dependencies
Specifies dependencies to install into the final image, including ansible-core, ansible-runner, Python packages,
system packages, and Ansible Collections. Ansible Builder automatically installs dependencies for any Ansible Col-
lections you install.
In general, you can use standard syntax to constrain package versions. Use the same syntax you would pass to dnf,
pip, ansible-galaxy, or any other package management utility. You can also define your packages or collections in
separate files and reference those files in the dependencies section of your execution environment definition file.
The following keys are valid for this section:
• ansible_core
• ansible_runner
• galaxy
• python
• python_interpreter
• system
See the dependencies section for more details.
images
Specifies the base image to be used. At a minimum you MUST specify a source, image, and tag for the base image. The
base image provides the operating system and may also provide some packages. We recommend using the standard
host/namespace/container:tag syntax to specify images.
See the images section for more details.
image verification
You can verify signed container images if you are using the podman container runtime.
See the image verification section for more details.
options
A dictionary of keywords/options that can affect builder runtime functionality. Valid keys for this section are:
• container_init
• cmd
• entrypoint
• package_pip
• package_manager_path
• skip_ansible_check
• relax_passwd_permissions
• workdir
• user
• tags
See the options section for more details.
version
6.9 Glossary
execution environment
execution environments are container images intended to be used as Ansible control nodes. Starting in version
2.0, ansible-runner. can make use of these images.
Control node
The machine or container running Ansible. See the Ansible documentation for a more comprehensive explana-
tion.
---
version: 3
images:
base_image:
name: [Link]/centos/centos:stream9 # vanilla image
dependencies:
# Use Python 3.9
python_interpreter:
package_system: python39
python_path: /usr/bin/python3.9
# Collections to be installed
galaxy:
collections:
- [Link]
additional_build_files:
# copy arbitrary files next to this EE def into the build context - we can refer to␣
˓→them later...
- src: files/[Link]
dest: configs
additional_build_steps:
prepend_base:
# copy a custom CA cert into the base image and recompute the trust database
# because this is in "base", all stages will inherit (including the final EE)
- COPY _build/configs/[Link] /usr/share/pki/ca-trust-source/anchors
- RUN update-ca-trust
In this example, the additional_build_files section allows you to add [Link] to the build context directory. Once this
file is copied to the build context directory, it can be used in the build process. In order to use, the file, we need to copy it
from the build context directory using the COPY directive specified in the prepend_base step of additional_build_steps
section.
Finally, you can perform any action based upon the copied file, such as in this example updating dynamic configuration
of CA certificates by running RUN update-ca-trust.
ã See also
---
version: 3
images:
base_image:
name: [Link]/centos/centos:stream9
dependencies:
python_interpreter:
package_system: python39
python_path: /usr/bin/python3.9
ansible_core:
package_pip: ansible-core==2.14.0
ansible_runner:
package_pip: ansible-runner==2.3.2
additional_build_steps:
prepend_base:
- ENV FOO=bar
- RUN echo $FOO > /tmp/[Link]
In this example, we are specifying an environment variable that may be required for the build process. In order to achieve
this functionality we are using the ENV variable definition in the prepend_base step of the additional_build_steps
section.
We can use the same environment variable in the later stage of the build process.
ã See also
---
version: 3
images:
base_image:
# Needs login
name: [Link]/ansible-automation-platform-23/ee-minimal-rhel8:latest
dependencies:
# No need to specify ansible-core or ansible-runner dependencies
# because they are included in the base image.
additional_build_steps:
prepend_galaxy:
# Environment variables used for Galaxy client configurations
- ENV ANSIBLE_GALAXY_SERVER_LIST=automation_hub
- ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_URL=[Link]
˓→automation-hub/content/xxxxxxx-synclist/
- ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_AUTH_URL=[Link]
˓→realms/redhat-external/protocol/openid-connect/token
# define a custom build arg env passthru - we still also have to pass
# `--build-arg ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN` to get it to pick it up␣
˓→from the env
- ARG ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN
options:
package_manager_path: /usr/bin/microdnf # downstream images use non-standard package␣
˓→manager
For security reasons, we do not want to store sensitive information in this case ANSI-
BLE_GALAXY_SERVER_AUTOMATION_HUB_TOKEN. You can use ARG directive to receive sensitive information
from the user as input. –build-args can be used to provide this information while invoking the ansible-builder
command.
ã See also
Then, use a custom RUN command within your EE definition file that references this secret:
---
version: 3
images:
base_image:
name: [Link]/centos/centos:stream9
additional_build_steps:
prepend_base:
- RUN --mount=type=secret,id=mytoken TOKEN=$(cat /run/secrets/mytoken) some_command
options:
skip_ansible_check: true
additional_build_steps:
append_final:
- RUN $PYCMD -m pip check
Using the $PYCMD -m pip calling form, instead of calling pip directly, will guarantee that the same Python executable
that was used to install the Python packages is used to do the validation.
C
Control node, 38
E
execution environment, 38
43