4.12. 安装 ansible-builder RPM
流程
在 RHEL 系统上,安装 ansible-builder RPM。这可以通过以下方法之一完成:
- 将 RHEL 框订阅到断开连接的网络上的 Satellite。
- 附加 Ansible Automation Platform 订阅并启用 AAP 存储库。
安装 ansible-builder RPM。
注意如果存在,则 Satellite 是首选的,因为如果底层构建主机已注册了底层构建主机,则 EE 镜像可以利用 Satellite 中的 RHEL 内容。
- 取消归档 AAP 安装捆绑包。
从包含的内容安装 ansible-builder RPM 及其依赖项:
$ tar -xzvf ansible-automation-platform-setup-bundle-2.3-1.2.tar.gz $ cd ansible-automation-platform-setup-bundle-2.3-1.2/bundle/el8/repos/ $ sudo yum install ansible-builder-1.2.0-1.el9ap.noarch.rpm python38-requirements-parser-0.2.0-4.el9ap.noarch.rpm
为您的自定义 EE 构建工件创建一个目录。
$ mkdir custom-ee $ cd custom-ee/
按照 https://ansible-builder.readthedocs.io/en/stable/definition/ 的文档创建 execution-environment.yml 文件,该文件定义了自定义 EE 的要求。覆盖
EE_BASE_IMAGE和EE_BUILDER_IMAGE变量,以指向私有自动化中心中提供的 EE。$ cat execution-environment.yml --- version: 1 build_arg_defaults: EE_BASE_IMAGE: '<hub_fqdn>/ee-supported-rhel8:latest' EE_BUILDER_IMAGE: '<hub_fqdn>/ansible-builder-rhel8:latest' dependencies: python: requirements.txt galaxy: requirements.yml
创建一个 ansible.cfg 文件,指向您的私有自动化中心,其中包含允许上传的凭证,如 admin 用户令牌。
$ cat ansible.cfg [galaxy] server_list = private_hub [galaxy_server.private_hub] url=https://<hub_fqdn>/api/galaxy/ token=<admin_token>
创建一个指向断开连接的 UBI 存储库镜像的 ubi.repo 文件(如果托管 UBI 内容,这可能是您的 Satellite)。
这是一个示例输出,其中
reposync用于镜像 UBI 仓库。$ cat ubi.repo [ubi-8-baseos] name = Red Hat Universal Base Image 8 (RPMs) - BaseOS baseurl = http://<ubi_mirror_fqdn>/repos/ubi-8-baseos enabled = 1 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release gpgcheck = 1 [ubi-8-appstream] name = Red Hat Universal Base Image 8 (RPMs) - AppStream baseurl = http://<ubi_mirror_fqdn>/repos/ubi-8-appstream enabled = 1 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release gpgcheck = 1
添加用于为私有自动化中心 web 服务器证书签名的 CA 证书。
- 对于自签名证书(安装程序默认),从您的私有自动化中心中生成文件 /etc/pulp/certs/root.crt 并将其命名为 hub-root.crt。
- 如果使用内部证书颁发机构来请求和签署私有自动化中心 web 服务器证书,请复制该 CA 证书,名为 hub-root.crt。
- 使用您的自定义 EE 镜像所需的内容创建 python requirements.txt 和 ansible 集合 requirements.yml。请注意,您需要的任何集合都应上传到您的私有自动化中心中。
使用 ansible-builder 创建用于构建 EE 镜像的上下文目录。
$ ansible-builder create Complete! The build context can be found at: /home/cloud-user/custom-ee/context $ ls -1F ansible.cfg context/ execution-environment.yml hub-root.crt pip.conf requirements.txt requirements.yml ubi.repo
将用于覆盖面向互联网的默认值的文件复制到上下文目录中。
$ cp ansible.cfg hub-root.crt pip.conf ubi.repo context/
编辑文件 context/Containerfile 并添加以下修改。
-
在第一个 EE_BASE_IMAGE 构建部分中,添加 ansible.cfg 和 hub-root.crt 文件,并运行
update-ca-trust命令。 - 在 EE_BUILDER_IMAGE 构建部分中,添加 ubi.repo 和 pip.conf 文件。
在最终的 EE_BASE_IMAGE 构建部分中,添加 ubi.repo 和 pip.conf 文件。
$ cat context/Containerfile ARG EE_BASE_IMAGE=<hub_fqdn>/ee-supported-rhel8:latest ARG EE_BUILDER_IMAGE=<hub_fqdn>/ansible-builder-rhel8:latest FROM $EE_BASE_IMAGE as galaxy ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS= USER root ADD _build /build WORKDIR /build # this section added ADD ansible.cfg /etc/ansible/ansible.cfg ADD hub-root.crt /etc/pki/ca-trust/source/anchors/hub-root.crt RUN update-ca-trust # end additions 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 RUN ansible-builder introspect --sanitize \ --user-pip=requirements.txt \ --write-bindep=/tmp/src/bindep.txt \ --write-pip=/tmp/src/requirements.txt # this section added ADD ubi.repo /etc/yum.repos.d/ubi.repo ADD pip.conf /etc/pip.conf # end additions RUN assemble FROM $EE_BASE_IMAGE USER root COPY --from=galaxy /usr/share/ansible /usr/share/ansible # this section added ADD ubi.repo /etc/yum.repos.d/ubi.repo ADD pip.conf /etc/pip.conf # end additions COPY --from=builder /output/ /output/ RUN /output/install-from-bindep && rm -rf /output/wheels
-
在第一个 EE_BASE_IMAGE 构建部分中,添加 ansible.cfg 和 hub-root.crt 文件,并运行
使用
podman命令在本地 podman 缓存中创建 EE 镜像。$ podman build -f context/Containerfile \ -t <hub_fqdn>/custom-ee:latest自定义 EE 镜像构建成功后,将其推送到私有自动化中心。
$ podman push <hub_fqdn>/custom-ee:latest
4.12.1. 在次版本间升级的工作流
要在 AAP 2 的次要发行本间升级,请使用此常规工作流。
流程
- 下载并解压缩最新的 AAP 2 安装捆绑包。
- 备份现有安装。
- 将现有安装清单文件复制到新的安装捆绑包目录中。
-
运行
./setup.sh以升级安装。
例如,要从 2.2.0-7 升级到 2.3-1.2,请确保两个设置捆绑包都位于安装发生的初始控制器节点上:
$ ls -1F ansible-automation-platform-setup-bundle-2.2.0-7/ ansible-automation-platform-setup-bundle-2.2.0-7.tar.gz ansible-automation-platform-setup-bundle-2.3-1.2/ ansible-automation-platform-setup-bundle-2.3-1.2.tar.gz
备份 2.2.0-7 安装:
$ cd ansible-automation-platform-setup-bundle-2.2.0-7 $ sudo ./setup.sh -b $ cd ..
将 2.2.0-7 清单文件复制到 2.3-1.2 捆绑包目录中:
$ cd ansible-automation-platform-setup-bundle-2.2.0-7 $ cp inventory ../ansible-automation-platform-setup-bundle-2.3-1.2/ $ cd ..
使用 setup.sh 脚本从 2.2.0-7 升级到 2.3-1.2 :
$ cd ansible-automation-platform-setup-bundle-2.3-1.2 $ sudo ./setup.sh