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?

AAPの実行環境(Execution Environment)を作成して登録するまで

Last updated at Posted at 2024-12-09

はじめに

こちらは エーピーコミュニケーションズ Advent Calendar 2024 の 10 日目の記事です。

実行環境(Execution Environment)を作成し、Ansible Automation Platform(AAP)に紐づけた話です。

前提

  • AWS上のEC2サーバにて構築
  • OS: RHEL 8.10
  • AAP 2.4 は作成済です

参考

以下の記事を参考にしています。

そもそも実行環境とは?という方はこちらから。

手順

手順は大きく以下の3ステップを実施しました。

  1. ansible-builder インストール
  2. ansible-builder によるイメージ作成
  3. AAP との紐づけ

1. ansible-builder インストール

以下のコマンドを実行して、リポジトリを有効化します。

dnf install --enablerepo=ansible-automation-platform-2.4-for-rhel-8-x86_64--rpms ansible-builder

[ec2-user@ip-10-0-0-223 ~]$ dnf install --enablerepo=ansible-automation-platform-2.4-for-rhel-8-x86_64--rpms ansible-builder
Updating Subscription Management repositories.
Red Hat Ansible Automation Platf     [===                            ] ---  B/s |   0  B     --:-- ETARed Hat Ansible Automation Platf     [===                            ] ---  B/s |   0  B     --:-- ETARed Hat Ansible Automation Platform 2.4 for RHEL 8 x86_64 (RPMs)       2.8 kB/s | 4.0 kB     00:01    
Dependencies resolved.
=======================================================================================================
 Package            Arch   Version        Repository                                              Size
=======================================================================================================
Installing:
 ansible-builder    noarch 3.0.1-1.el8ap  ansible-automation-platform-2.4-for-rhel-8-x86_64-rpms  66 k
Installing dependencies:

(中略)

Complete!

2. ansible-builder によるイメージ作成

下準備

まずはイメージ作成の下準備です。以下のファイルを作成していきます。

./
└─ /opt/
    └─ /builder/
        └─ /test/
            ├─ execution-environment.yml
            ├─ requirements.yml
            ├─ requirements.txt
            └─ bindep.txt

execution-environment.yml

ARG ANSIBLE_GALAXY_SERVER_AUTOMATION_HUB_TOKENには、ここで払い出したオフライントークンを記入してください(要RedHatアカウント)。

---
version: 3

build_arg_defaults:
  ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: '--pre'

dependencies:
  galaxy: requirements.yml
  python: requirements.txt
  system: bindep.txt

images:
  base_image:
    name: registry.redhat.io/ansible-automation-platform-24/ee-minimal-rhel8: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=<払いだしたToken>

  prepend_final: |
    RUN whoami
    RUN cat /etc/os-release
  append_final:
    - RUN echo This is a post-install command!
    - RUN ls -la /etc

requirements.yml

ここにはインストールしたいコレクションリストを記載します。

今回はcisco.iosコレクションをいれてみました。

---
collections:
  - name: cisco.ios

requirements.txt

追加のPython要件があれば、こちらでインストールする。

下記は公式サイトで記載の内容。

boto>=2.49.0
botocore>=1.12.249
pytz
python-dateutil>=2.7.0
awxkit
packaging
requests>=2.4.2
xmltodict
azure-cli-core==2.11.1
openshift>=0.6.2
requests-oauthlib
openstacksdk>=0.13
ovirt-engine-sdk-python>=4.4.10

bindep.txt

これはファイルだけ作成しました。

ansible-builder コマンドを実行

下準備ができたら、ansible-builder でイメージ作成していきます。

ansible-builder build

オプションに -t <タグ名>をつけることで任意のタグ名を付けられます。なにも指定しなければansible-execution-envがタグ名となります。

[ec2-user@ip-10-0-0-223 test]$ sudo ansible-builder build
Running command:
  podman build -f context/Containerfile -t ansible-execution-env:latest context
Complete! The build context can be found at: /opt/builder/test/context
[ec2-user@ip-10-0-0-223 test]$ sudo podman images
REPOSITORY                                                          TAG         IMAGE ID      CREATED             SIZE
localhost/ansible-execution-env                                     latest      f0d3c062641b  26 seconds ago      378 MB

(以下略)

3.AAP との紐づけ

ここまでで実行環境のイメージを作成できましたが、このイメージをAAPで使用できるようにする必要があります。

もう少し具体的には、AWXユーザ内にこの実行環境を入れる必要があります。

イメージをコピーして圧縮 → AWXユーザに所有者変更 → AWXユーザで展開を実施します。

途中でユーザをAWXユーザに変更しています。

[ec2-user@ip-10-0-0-223 test]$ sudo podman save -o /tmp/test_ee.tar localhost/ansible-execution-env
Copying blob cb973d48271c [--------------------------------------] 0.0b / 89.7MiB | 0.0 b/s

(中略)

[ec2-user@ip-10-0-0-223 test]$ sudo chown awx:awx /tmp/test_ee.tar
[ec2-user@ip-10-0-0-223 test]$ su - awx
[awx@ip-10-0-0-223 ~]$ podman load -i /tmp/test_ee.tar
Getting image source signatures
Copying blob cb973d48271c skipped: already exists  
Copying blob cb973d48271c skipped: already exists  

(中略)

Writing manifest to image destination
Loaded image: localhost/ansible-execution-env:latest
[awx@ip-10-0-0-223 ~]$ podman images
REPOSITORY                                                            TAG         IMAGE ID      CREATED         SIZE
localhost/ansible-execution-env                                       latest      f0d3c062641b  44 minutes ago  378 MB

あとは、AAPのGUI画面で実行環境イメージを登録します。

実行環境追加で実行環境の新規作成をします。

名前: test_ee
イメージ: localhost/ansible-execution-env
プル: 実行前にコンテナーをプルしない
説明: 
組織: Default
レジストリーの認証情報: 

スクリーンショット 2024-12-09 202736.png

デフォルトで存在するジョブテンプレートに実行環境をセットして起動してみます。

スクリーンショット 2024-12-09 203001.png

スクリーンショット 2024-12-09 203023.png

問題なさそうですね。

ちなみにcisco.iosコレクションが入っていることも確認できました。

スクリーンショット 2024-12-09 203053.png

まとめ

AAPで利用する実行環境を作成してAAPに紐づけるところまでやってみました。

CLI上でコレクションをインストールすることに比べると、結構な手数が増えるのことが身を染みてわかりました。

次は作成したイメージをGitlabで管理するようなこともやってみたいですね。

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?