1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ansible-builder を使用した Ansible Automation Platform の カスタマイズ実行環境(Execute enviroment) の作成

Posted at

はじめに

Ansible Automation Platformでは、Playbookの実行に必要なライブラリやCollectionをコンテナイメージとしてパッケージ化した 実行環境:Execution Environment: EEを使用します。


標準のイメージでは不足する Collection や Python ライブラリがある場合、ansible-builder というツールを使って独自の EE を作成する必要があります。今回は、RHEL 9 (ppc64le) 環境において、カスタマイズ EE を作成し、Automation Hub へプッシュ、そして Automation Controller で実際にジョブを動かすまでの一連の流れをまとめました。


参考ドキュメント:

Ansible Automation Platform 2.6: 実行環境の作成と使用

ansible-builder installation

ansible-builder Execution environment definition


動画

当記事のご参考動画です。音声動画で理解の一助にお役立てください。


環境

今回の検証環境は以下の通りです。

  • OS: Red Hat Enterprise Linux 9.6 (ppc64le)

  • Software: Ansible Automation Platform 2.6.4

  • Container Base Image: ee-minimal-rhel9:latest

Powerアーキテクチャ(ppc64le)を使用していますが、特段 x86 と違いはありません。


ansible-builder の導入

まずは EE をビルドするためのツール ansible-builder をインストールします。

前提として、pip コマンドを使用するために、python3-pip のインストールを実施します。
(dnf 設定実行済みです)

# dnf install python3-pip

~ 省略 ~ 

Installed:
  python3-pip-21.3.1-1.el9.noarch

Complete!
  • コマンドの確認
# which pip
/usr/bin/pip

# which pip3
/usr/bin/pip3
  • ansible-builder のインストール
# pip3 install ansible-builder
Collecting ansible-builder
  Downloading ansible_builder-3.1.1-py3-none-any.whl (46 kB)

~ 省略 ~ 

Installing collected packages: pbr, Parsley, distro, bindep, ansible-builder
Successfully installed Parsley-1.3 ansible-builder-3.1.1 bindep-2.13.0 distro-1.9.0 pbr-7.0.3
  • 確認
# which ansible-builder
/usr/local/bin/ansible-builder
#

システム全体にインストールする際は、パーミッションに注意が必要です。本番運用では仮想環境 (venv) の利用も推奨されます。


ビルド定義の作成

ビルドに必要な定義ファイルを作成します。

  • 今回は「AAP自身の構成管理」や「各種ユーティリティ」を含む EE を作成します。
     ここからは rootless にするため一般ユーザーで実行しています。
$ podman login registry.redhat.io
Username: xxxx
Password:
Login Succeeded!
  • ベースとなる rhel9 minimal イメージを registry.redhat.io からプルします。
$ podman pull registry.redhat.io/ansible-automation-platform-26/ee-minimal-rhel9:latest
  • 確認
$ podman images | grep ee-minimal
registry.redhat.io/ansible-automation-platform-26/ee-minimal-rhel9            latest      149e1f5e8a4c  6 weeks ago  388 MB
  • ディレクトリ準備
$ mkdir aapconfig-test
$ cd aapconfig-test
  • requirements.yml (追加する Collection の定義)
requirements.yml
---
collections:
  - name: ansible.posix             # ACL, Firewalld, Mount, Sysctl 等
  - name: community.general         # 多種多様なモジュール群
  - name: infra.aap_configuration   # AAP 自身の構成管理用
  - name: community.crypto          # 証明書作成、CSR、OpenSSL、ACME 等
  - name: ansible.utils             # IPアドレス計算、データ検証、フォーマット変換等

  • execution-environment.yml (EEの全体定義)
execution-environment.yml
version: 3

images:
  base_image:
    name: registry.redhat.io/ansible-automation-platform-26/ee-minimal-rhel9:latest

dependencies:
  galaxy: requirements.yml

options:
  package_manager_path: /usr/bin/microdnf
  • ee-minimal イメージは軽量化のため dnf の代わりに microdnf が採用されています。そのため package_manager_path の明示的な指定が必要です。

カスタム EE のビルド

  • 定義ファイルを確認
$ ls -ltr
total 8
-rw-r--r--. 1 ansible ansible 396 Jan 29 00:57 requirements.yml
-rw-r--r--. 1 ansible ansible 304 Jan 29 01:04 execution-environment.yml
  • ビルド実行
$ ansible-builder build -t aapconfig-test:0.1
Running command:
  podman build -f context/Containerfile -t aapconfig-test:0.1 context
Complete! The build context can be found at: /home/ansible/pod/aapconfig-test/context
  • イメージの確認
$ podman images | grep aapconfig
REPOSITORY                                                                    TAG         IMAGE ID      CREATED             SIZE
localhost/aapconfig-test                                                      0.1         15e23d646840  10 seconds ago      610 MB

ビルドが完了すると、カレントディレクトリに context ディレクトリが生成されます。
ここにはビルドに使用された Containerfile やスクリプトが含まれており、ビルドプロセスの詳細を確認することが可能です。

$ ls -l
total 8
drwxr-xr-x. 3 ansible ansible  41 Jan 29 01:13 context
-rw-r--r--. 1 ansible ansible 445 Jan 29 01:12 execution-environment.yml
-rw-r--r--. 1 ansible ansible 396 Jan 29 00:57 requirements.yml

コンテナファイルやビルドログがあります。

$ ls -lR ./context/
./context/:
total 4
-rw-r--r--. 1 ansible ansible 2721 Jan 29 02:20 Containerfile
drwxr-xr-x. 3 ansible ansible   45 Jan 29 02:20 _build

./context/_build:
total 4
-rw-r--r--. 1 ansible ansible 396 Jan 29 00:57 requirements.yml
drwxr-xr-x. 2 ansible ansible 148 Jan 29 02:20 scripts

./context/_build/scripts:
total 52
-rwxr-xr-x. 1 ansible ansible  6192 Jan 29 00:24 assemble
-rwxr-xr-x. 1 ansible ansible  3474 Jan 29 00:24 check_ansible
-rwxr-xr-x. 1 ansible ansible  1767 Jan 29 00:24 check_galaxy
-rwxr-xr-x. 1 ansible ansible  5909 Jan 29 00:24 entrypoint
-rwxr-xr-x. 1 ansible ansible  3599 Jan 29 00:24 install-from-bindep
-rw-r--r--. 1 ansible ansible 17551 Jan 29 00:24 introspect.py
-rwxr-xr-x. 1 ansible ansible  1466 Jan 29 00:24 pip_install

コンテナ動作確認

ビルドしたイメージを起動し、意図した Collection がインストールされているか確認します。

  • Ansible バージョンの確認
$ podman run --rm localhost/aapconfig-test:0.1  ansible --version
ansible [core 2.15.13]
  config file = None
  configured module search path = ['/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.25 (main, Jan 14 2026, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-11)] (/usr/bin/python3)
  jinja version = 3.1.6
  libyaml = False
  • コレクションリストの確認

[ansible@aap264-s1 scripts]$  podman run --rm localhost/aapconfig-test:0.1 ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection              Version
----------------------- -------
ansible.posix           2.1.0
ansible.utils           6.0.1
community.crypto        3.1.0
community.general       12.3.0
infra.aap_configuration 3.3.0

requirements.yml に指定した collections が導入できています。


Automation Hub への登録

作成した EE を共有するため、Private Automation Hub へプッシュします。

Automation Hub 側での準備:

  • 管理画面から「実行環境」の名前空間(例: test)を作成します。

スクリーンショット 2026-01-29 18.06.45.png

スクリーンショット 2026-01-29 18.07.08.png

スクリーンショット 2026-01-29 18.10.23.png


Private Automation Hub への push

ローカルのレジストリにログイン (インストールの際に指定した Automation Hub のIPを使用します)

$ podman login xxx.xxx.xxx.xxx
Username: admin
Password: <インストール時に Hub に設定したパスワード> 
Login Succeeded!

automation Hub にpush するイメージへタグを付けます
ここで、名前空間も指定が必要になります。xxx.xxx.xxx.xxx/test/aapconfig-test:0.1

$ podman tag localhost/aapconfig-test:0.1 xxx.xxx.xxx.xxx/test/aapconfig-test:0.1

タグ付きのイメージが確認できました。

$ podman images
REPOSITORY                                                                    TAG         IMAGE ID      CREATED      SIZE
localhost/aapconfig-test                                                      0.1         15e23d646840  2 hours ago  610 MB
xxx.xxx.xxx.xxx/test/aapconfig-test                                           0.1         15e23d646840  2 hours ago  610 MB

push を実行します。

$ podman push xxx.xxx.xxx.xxx/test/aapconfig-test:0.1
Getting image source signatures
Copying blob f4815be8b0ae done   |
Copying blob e3a69733ec60 done   |
Copying blob dd9e142c85c2 done   |
Copying blob b8f51ecd4897 done   |
Copying blob 8734e5639da2 done   |
Copying blob 7263a0ee255b done   |
Copying blob a28980092193 done   |
Copying blob fc1db6c296b9 done   |
Copying blob 35d106ba1e85 done   |
Copying blob e7dcd34a9967 done   |
Copying blob 2e5e885e272c done   |
Copying blob c00e13bc57f0 done   |
Copying blob 65c318a730f2 done   |
Copying blob 4bcbb4a36f10 done   |
Copying config 15e23d6468 done   |
Writing manifest to image destination

コマンド実行後、Web UI の方で、Automation Content の 実行環境に対象が作成されました。

スクリーンショット 2026-01-29 18.18.42.png


Automation Execution 実行環境への登録

Automation Controller (Execution) でこの EE を使用できるように設定します。

認証情報の作成

現時点で、Automation Hub の認証情報は存在していません。

スクリーンショット 2026-01-29 18.28.41.png

Controller 側で「コンテナレジストリ」タイプの認証情報を作成し、Hub へのログイン情報を登録します。

スクリーンショット 2026-01-29 18.30.43.png

スクリーンショット 2026-01-29 18.33.00.png

実行環境の登録

続いて、Private Automation Hub に登録した実行環境を Automation Execution 環境の実行環境で使用できるようにします。

"実行環境の作成" を押します。

スクリーンショット 2026-01-29 18.27.21.png

「実行環境」メニューから新規作成し、Hub 上のイメージパスを指定します。

スクリーンショット 2026-01-29 18.35.38.png


稼働確認

ジョブテンプレートに実行環境を設定

既存のジョブテンプレート(Hello World)の「実行環境」欄を、今回作成した aapconfig-test:0.1 に変更して保存します。

スクリーンショット 2026-01-29 18.37.10.png

"Hello World Job" テンプレートを編集します。
実行環境に作成した aapcofig-test を設定します。

スクリーンショット 2026-01-29 18.38.19.png

ジョブテンプレートを保存。

"テンプレートの起動" を実行します

スクリーンショット 2026-01-29 18.39.54.png

テンプレートを起動し、無事にジョブが完了することを確認しました。
図1.png


おわりに

本記事では、ansible-builder を用いたカスタム Execution Environment(EE)のビルドから、Private Automation Hub への登録、Automation Controller での実行までの一連の流れを紹介しました。

今回は Collection の追加のみでしたが、同じ手順で python-requirements.txt による Python ライブラリの追加や、bindep.txt による OS パッケージの追加にも簡単に拡張できます。

Private Automation Hub を活用することで、チーム全体で統一された実行環境を共有・管理でき、より安定した運用が実現できます。

カスタム実行環境を構築する際の参考になれば幸いです。

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?