Ansible Builder
repository·devel·Indexed 43 days ago
https://github.com/ansible/ansible-builderA tool for automating the creation of Ansible Execution Environments. It leverages collection schemas and user-defined YAML configurations to build consistent, containerized environments using RPM-based images. Features include dependency aggregation for Python and system packages, support for the 3.x definition schema, and an `introspect` command to verify collection metadata.
What's inside Ansible Builder
- Ansible Builder is a tool designed to automate the creation of Ansible execution environments. It uses schemas and tooling defined within various Ansible Collections, as well as user-defined configurations, to build consistent container images for running Ansible playbooks.
Top-level sections in Ansible Builder 3.x definition files
develAn Ansible Builder 3.x execution environment definition file is composed of seven top-level sections:
additional_build_files: Files to be added to the build context.additional_build_steps: Custom commands for specific build phases.build_arg_defaults: Default build arguments.dependencies: Packages and collections to install.images: Base image configuration.options: Runtime functionality keywords.version: The schema version (must be3).
Symlink behavior in additional_build_files
develIn version 3.2, when using theadditional_build_filessection of an Execution Environment (EE) definition, Ansible Builder now copies the symlink itself instead of dereferencing it to copy the target file. This prevents build errors that previously occurred if a symlink pointed to a non-existent file.Understand Execution Environments
develAn execution environment is a container image designed to serve as an Ansible control node. It packages the Ansible engine along with the specific collections, Python libraries, and system dependencies required to run your automation. Starting with version 2.0,ansible-runnercan utilize these images to provide a consistent and isolated runtime for Ansible tasks.Base image requirements for ansible-builder
develAnsible Builder requires RPM-based container images for its execution environments. These are images that use
dnformicrodnffor package management.Unsupported distributions:
- Debian
- Ubuntu
- Alpine
How Ansible Builder execution steps work
develAnsible Builder operates in two distinct stages:
- Creation Stage: Generates a build instruction file (
Containerfilefor Podman,Dockerfilefor Docker) and a build context based on your execution environment definition file. This is performed by theansible-builder createcommand. - Build Stage: Runs a containerization tool (Podman or Docker) to build the image using the generated instructions and context. This is performed by the
ansible-builder buildcommand, which executes both stages sequentially.
Use
ansible-builder createif you only want to generate the build artifacts (instructions and context) to build the image on a different platform or at a later time.- Creation Stage: Generates a build instruction file (
Understand Python requirements changes in Ansible Builder 3.1
develIn version 3.1,
ansible-builderchanged how Python and system requirements are handled by simplifying dependency parsing and removing an unmaintained external library.Key changes include:
- PEP 508 Standard: Python requirements files are now expected to follow the PEP 508 standard. While
ansible-builderignores comments (lines starting with#), any non-compliant line will trigger a warning and be passed topipunmodified. This may expose dependency resolution issues that were previously hidden by the version 3.0 sanitizer. - Removal of Dependency Sanitization:
ansible-builderno longer combines duplicate dependencies into a single entry. If multiple collections or requirement files list the same dependency, they will now appear as separate entries in the combined requirements file. For example,fooandfoo>=1.0will no longer be merged intofoo,foo>=1.0, but will instead appear as two distinct lines.
- PEP 508 Standard: Python requirements files are now expected to follow the PEP 508 standard. While
Configure base images for Execution Environments
develAnsible Builder requires RPM-based images that use
dnf(or compatible) package management.Supported/Compatible Base Images:
docker.io/redhat/ubi9:latestquay.io/rockylinux/rockylinux:9quay.io/centos/centos:stream9registry.fedoraproject.org/fedora:38registry.redhat.io/ansible-automation-platform-23/ee-minimal-rhel8:latest(requires account)
Unsupported Images:
- Non-RPM images such as Debian, Ubuntu, or Alpine are not supported.
Configure additional build files and steps in v3.0
develAnsible Builder 3.0 provides new ways to inject files and custom commands into the container build process.
additional_build_files
Use this section to specify files that should be added to the build context directory. Once added, these files can be referenced or copied by
additional_build_stepsduring any stage of the build.additional_build_steps
You can specify fine-grained build steps or custom commands for any build phase. These commands are inserted directly into the generated
ContainerfileorDockerfile. Commands must follow the syntax rules of your container runtime (e.g., Podman or Docker).Available build step hooks:
prepend_base/append_baseprepend_galaxy/append_galaxyprepend_builder/append_builderprepend_final/append_final
Understand the Control Node concept
develA Control node is the machine or container where Ansible is actually executed. It is the environment that initiates connections to managed nodes and runs playbooks. In the context ofansible-builder, the execution environment you build becomes the containerized control node.Bindep parse error detection in version 3.2
develAnsible Builder 3.2 now provides improved error detection for
bindep.txtfiles. If thebindepprogram encounters unparsable content and exits with code 2, the build process will now fail immediately with the messageError: bindep.txt contains unparsable contentand exit with code 2.Requirement: Your container image must have
bindepversion 2.14.0 or higher installed for this immediate failure behavior to work. Versions below 2.14.0 will not halt execution on unparsable content.Understand the Ansible Builder 3.x definition schema
develThe Ansible Builder 3.x execution environment definition file is composed of seven top-level sections:
additional_build_files: Files to be added to the build context.additional_build_steps: Custom build instructions (prepend/append) for different stages of the build.build_arg_defaults: Default values for build arguments.dependencies: Definitions for Ansible core, runner, galaxy collections, python packages, and system packages.images: Configuration for the base image used in the build.options: Additional builder configuration options.version: The schema version (must be set to3for version 3 features).