どうも、Tです。
AWXで利用するカスタムEEをPodman上で作成した備忘録です。
目次
環境
Oracle Linux(PodmanのホストOS)
$ cat /etc/redhat-release Red Hat Enterprise Linux release 10.0 (CentOS Stream) $ uname -a Linux k-podman.k.local.lab 6.12.0-100.28.2.el10uek.x86_64 #1 SMP PREEMPT_DYNAMIC Mon May 19 19:28:24 PDT 2025 x86_64 GNU/Linux
Podman
$ podman --version podman version 5.4.0
Ansible Builder
$ pip3 list Package Version ------------------------- --------- ansible-builder 3.1.0
やりたいこと
AWXでPalybookを実行するときは、Execution Environments(AWX EE)コンテナで行われます。AWXをデプロイした時点で2種類のEEコンテナが利用できるようになっていたため、それぞれが動いているansible coreバージョンは以前しらべてみました。

このAWX EEは、そのままでも使えるのですが、自分独自のAWX EEコンテナ(以下、カスタムEEといいます)を作って利用することもできます。明確な指針はありませんが、以下のような場合はカスタムEEを利用する必要があります。
- コレクションをコンテナに事前に組み込んでおく
- コレクションの関係でPythonバージョンなどの要件を満たす必要がある
- Pythonライブラリなど追加する必要がある
- 設定ファイルなどを書き換える必要がある
- その他、EEコンテナに含まれるバージョンを指定する必要があるなど。
今回は、利用したいコレクションがPythonバージョンやライブラリの要件を満たせなかったため、カスタムEEを作成することにしました。
Ansible Builderとは
EEコンテナは、名前の通りコンテナで動作します。カスタムEEを作成するとは、コンテナイメージを作ることです。
Ansible Bulderは、作成した定義ファイルに従いPodmanもしくはDockerでコンテナイメージをビルドしてくれるツールです。
事前準備(podmanインストール)
カスタムEEを作成するためには、コンテナ環境(Docker or Podman)が必要です。
今回はPodmanを利用しました。Podmanのインストール方法は、下記の記事にまとめています。

ansible-builderインストール
下記のドキュメントを参考にanbile-builderをインストールします。
PyPIでインストールするため、Pythonがバージョン要件(Python 3.9以上)を満たしていることを確認します。
$ python --version Python 3.12.9
PyPIを利用するために必要なpipパッケージをインストールします。
$ sudo dnf install python3-pip
ansible-builderをインストールします。
$ sudo pip3.12 install ansible-builder
ansible-builderがインストールされたことを確認します。
$ sudo pip3.12 list Package Version ------------------------- --------- ansible-builder 3.1.0 --割愛--
ansible-builderコマンドが実行できることを確認します。
$ sudo ansible-builder --version 3.1.0
実行環境定義ファイル作成
カスタムEEは、実行環境定義ファイル(execution-environment.yml。以下、EEファイルといいます)に従ってビルドされます。必要な定義を指定したEEファイルを作っていきます。
execution-environment.yml作成
作業用ディレクトリを作成して移動します。
$ mkdir -p ~/ansible-builder/k-awx-ee $ cd ~/ansible-builder/k-awx-ee
EEファイルを作成します。
$ vi execution-environment.yml
下記の内容を記載します。
定義の項目や記載方法は、下記のドキュメントにまとめられています。
--- version: 3 images: base_image: name: registry.access.redhat.com/ubi9:latest dependencies: ansible_core: package_pip: ansible-core==2.19.0 ansible_runner: package_pip: ansible-runner==2.4.1 galaxy: collections: - name: ansible.posix - name: ansible.windows - name: awx.awx - name: community.general - name: community.proxmox - name: community.windows python_interpreter: package_system: python3.12 python_path: /usr/bin/python3.12 python: - six - psutil - proxmoxer - requests additional_build_steps: append_base: - RUN alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 0
上から順に紹介しますが、細かい内容のため不要な方は読み飛ばしてください。
version:
version: 3
EEファイルのスキーマバージョンです。Ansible Builder 3系を利用する場合バージョン3を指定する必要があります。
images:
images: base_image: name: registry.access.redhat.com/ubi9:latest
カスタムEEのベースとなるコンテナイメージを指定しています。
dependencies:
dependencies(依存関係)セクションでは、Python・ansible-core、ansible-runner、ansibleコレクションなどカスタムEEに導入する依存関係を定義します。
ansible_core:
ansible_core: package_pip: ansible-core==2.19.0
ansible-coreは、ランタイム・組み込みモジュール・コマンドラインツールセットが含まれます。
カスタム時の最新バージョンを指定しています。

ansible_runner:
ansible_runner: package_pip: ansible-runner==2.4.1
ansible-runnerは、インターフェースの抽象化を行うものです。具定例を挙げるとAnsibleでは、playbookの実行にansible-playbookコマンドを使いますが、AWX(EEコンテナ)の場合、内部的にはansible-runnerコマンドとなり、ansible-playbookの変更があったとしても、継続して利用できるようにするた共有インターフェースを提供します。
ansible-runnerについては下記ドキュメントに記載されています。
カスタム時の最新バージョンを指定しています。
galaxy:
galaxy: collections: - name: ansible.posix - name: ansible.windows - name: awx.awx - name: community.general - name: community.proxmox - name: community.windows
GalaxyからインストールするAnsibleコレクションを指定しています。バージョン指定していないので依存関係を満たせる範囲の最新バージョンが導入されます。
python_interpreter:
python_interpreter: package_system: python3.12 python_path: /usr/bin/python3.12
python_interpreterセクションでは、PythonパッケージとPythonコマンドのPATHを定義しています。
python:
python: - six - psutil - proxmoxer - requests
Pythonのインストール要件です。追加で必要となるPythonライブラリを定義しています。
additional_build_steps:
additional_build_steps: append_base: - RUN alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 0
additional_build_stepsセクションでは、ビルドフェーズにカスタムビルドコマンドを指定できます。python3.12コマンドをpython3コマンドとして実行できるように指定しています。
今回導入しているベースイメージubi9では、python3.12はpyhon3のシンボリックリンクになっているはずのため問題ないと思いますが、下記のような問題があったため念のため設定しています。
Appendix
EEファイルを用いたビルドの流れは下記のドキュメントに記載されています。この後のビルドで失敗するようなことがあれば、定義している内容とビルドの流れを意識して切り分けが必要になります。
- Base : Podman または Docker を使用して定義したベースイメージをプルし、Python バージョン(定義されていてベースイメージ上の Python と異なる場合)、pip、ansible-runner、ansible-core または ansible をインストールします。ビルドプロセスの後の 3 つのステージはすべて、Base ステージの出力に基づいてビルドされます。
- Galaxy : 定義したコレクションを Galaxy からダウンロードし、ファイルとしてローカルに保存します。
- ビルダー: 定義した他のパッケージ (Python パッケージとシステム パッケージ) をダウンロードし、ファイルとしてローカルに保存します。
- Final : 最初の 3 つのステージを統合し、Base ステージの出力に保存されているすべてのファイルをインストールし、すべてのコンテンツを含む新しいイメージを生成します。
Execution Environmentのビルド
下記のドキュメントを参考に、EEファイルを利用してカスタムEEをビルドします。
EEファイルと指定してビルドを実行します。
$ ansible-builder build --tag=k-awx-ee:v1.0 --file=execution-environment.yml --verbosity 3 Ansible Builder is generating your execution environment build context. File context/_build/requirements.yml will be created. File context/_build/requirements.txt will be created. File context/_build/scripts/assemble will be created. File context/_build/scripts/install-from-bindep will be created. File context/_build/scripts/introspect.py will be created. File context/_build/scripts/check_galaxy will be created. File context/_build/scripts/check_ansible will be created. File context/_build/scripts/pip_install will be created. File context/_build/scripts/entrypoint will be created. Ansible Builder is building your execution environment image. Tags: k-awx-ee:v1.0 Running command: podman build -f context/Containerfile -t k-awx-ee:v1.0 context [1/4] STEP 1/17: FROM registry.access.redhat.com/ubi9:latest AS base --割愛-- Complete! The build context can be found at: /home/xxxx/ansible-builder/k-awx-ee/context
完了するとビルドコンテキスト(contextディレクトリ)が作成されます。
$ ls context execution-environment.yml $ sudo dnf install tree $ tree context/ context/ ├── Containerfile └── _build ├── requirements.txt ├── requirements.yml └── scripts ├── assemble ├── check_ansible ├── check_galaxy ├── entrypoint ├── install-from-bindep ├── introspect.py └── pip_install
カスタムEEのコンテナイメージがビルドされました。
$ podman images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/k-awx-ee v1.0 97d9f2250361 10 minutes ago 406 MB <none> <none> bdb5e9ecc542 10 minutes ago 408 MB <none> <none> bd82fad4b9c1 10 minutes ago 370 MB registry.access.redhat.com/ubi9 latest d5b051408ebc 12 days ago 217 MB
簡単な確認
カスタムEEをpodmanで動作させることにより、定義した内容になっているか簡易な確認が行えます。
$ podman run -it --rm k-awx-ee:v1.0 bash bash-5.1$ python3 --version Python 3.12.9 bash-5.1$ pip3 list Package Version ------------------ ----------- ansible-core 2.19.0 ansible-runner 2.4.1 --割愛-- bash-5.1$ ansible-galaxy collection list # /usr/local/lib/python3.12/site-packages/ansible/_internal/ansible_collections Collection Version -------------------- ------- ansible._protomatter 2.19.0 # /usr/share/ansible/collections/ansible_collections Collection Version -------------------- ------- ansible.posix 2.1.0 ansible.windows 3.2.0 awx.awx 24.6.1 community.general 11.1.0 community.proxmox 1.2.0 community.windows 3.0.1
参考



まとめ
初めてカスタムEEを作ってみましたが、最近のanbile-builderでは以前より多くのことが柔軟にできるようになった反面、あまりにも数が多すぎて何を指定すればよいのか?もしくはだめなのか?というのが非常にわかりにくいです。
作成したカスタムEEをAWXで使う方法については、下記の記事にまとめています。
