2.4. 构建定义文件
您可以使用 Ansible Builder 创建执行环境。构建新的执行环境涉及定义,该定义指定要包含在执行环境中的内容,如集合、Python 要求和系统级软件包。
安装 Ansible Builder 后,您可以创建一个定义文件,Ansible Builder 用来创建自动化执行环境镜像。Ansible Builder 通过读取和验证定义文件来创建一个自动化执行环境镜像,然后创建一个 Containerfile,最后将 Containerfile 传递给 Podman,然后打包并创建自动化执行环境镜像。您创建的定义文件必须是 YAML 格式,带有 .yaml 或 .yml 扩展名,并包含不同的部分。默认定义文件名(如果未提供)是 execution-environment.yml。有关定义文件部分的更多信息,请参阅 定义文件内容的明细。
以下是版本 3 定义文件的示例:每个定义文件都必须指定其使用的 Ansible Builder 功能集的主版本号。如果没有指定,Ansible Builder 默认为版本 1,使大多数新功能和定义关键字不可用。
version: 3
build_arg_defaults:
ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: '--pre'
dependencies:
galaxy: requirements.yml
python:
- six
- psutil
system: bindep.txt
images:
base_image:
name: registry.redhat.io/ansible-automation-platform-26/ee-minimal-rhel9:latest
# Custom package manager path for the RHEL based images
options:
package_manager_path: /usr/bin/microdnf
additional_build_steps:
prepend_base:
- RUN echo This is a prepend base command!
prepend_galaxy:
# Environment variables used for Galaxy client configurations
- ENV ANSIBLE_GALAXY_SERVER_LIST=automation_hub
- ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_URL=https://console.redhat.com/api/automation-hub/content/published/
- ENV ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_AUTH_URL=https://sso.redhat.com/auth/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
prepend_final: |
RUN whoami
RUN cat /etc/os-release
append_final:
- RUN echo This is a post-install command!
- RUN ls -la /etc
-
build_arg_defaults:列出构建参数的默认值。 -
dependencies:指定各种要求文件的位置。 -
镜像:指定要使用的基础镜像。红帽支持仅为 redhat.registry.io 基础镜像提供。 -
options: 指定可能会影响构建器运行时功能的选项。 -
additional_build_steps: 命令用于其他自定义构建步骤。