From 8e379429786a7c5e943ba42ec073a3693d4abfea Mon Sep 17 00:00:00 2001 From: kurokobo <2920259+kurokobo@users.noreply.github.com> Date: Sat, 24 Jun 2023 16:20:15 +0900 Subject: [PATCH] feat: correct prepend_galaxy to make customized file is used in galaxy stage --- builder/README.md | 29 ++++++++++++++++------------- builder/execution-environment.yml | 11 ++++++----- builder/files/ansible.cfg | 7 +++++-- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/builder/README.md b/builder/README.md index 029e0d5..f6888f2 100644 --- a/builder/README.md +++ b/builder/README.md @@ -43,7 +43,7 @@ In such cases, you need to add Ansible collections, Python packages, and RPM pac To build custom EE, there is a tool called Ansible Builder. You can build your own custom EE with any Ansible collections, Python packages, and RPM packages added. - [ansible/ansible-builder](https://github.com/ansible/ansible-builder) -- [Introduction — ansible-builder documentation](https://ansible-builder.readthedocs.io/en/stable/) +- [Introduction to Ansible Builder — ansible-builder documentation](https://ansible.readthedocs.io/projects/builder/en/latest/) This repository includes ready-to-use files as an example to use Ansible Builder. You can clone my repository to start with my ready-to-use example files. @@ -77,11 +77,14 @@ This repository contains [`execution-environment.yml` as a minimal ready-to-use - Use `quay.io/centos/centos:stream9-minimal` as the base image - Use Python `3.11` as Python interpreter - Use Ansible `2.15.*` and Ansible Runner `2.3.*` to run playbooks on EE -- Add Ansible collections that listed in [`dependencies/requirements.yml`](dependencies/requirements.yml) -- Add Python packages that listed in [`ependencies/requirements.txt`](ependencies/requirements.txt) - Add RPM Packages that listed in [`dependencies/bindep.txt`](dependencies/bindep.txt) for basic remote connection and debugging +- Add Python packages that listed in [`dependencies/requirements.txt`](ependencies/requirements.txt) +- Add Ansible collections that listed in [`dependencies/requirements.yml`](dependencies/requirements.yml) +- Customize configuration for `ansible-galaxy` (`additional_build_files` and `additional_build_steps`) + - Add customized `ansible.cfg` to the context (`additional_build_files`) + - Place customized file as `~/.ansible.cfg` for the stage that `ansible-galaxy` is invoked (`prepend_galaxy` under `additional_build_steps`) - Run additional commands during build steps (`additional_build_steps`) - - In this example, to allow the hard-coded interpreter name (`python3`) passed by AWX, `alternatives` command is appended under `append_base` to make the binary `/usr/bin/python3.11` executable as command `python3` + - To allow the hard-coded interpreter name (`python3`) passed by AWX, `alternatives` command is appended under `append_base` to make the binary `/usr/bin/python3.11` executable as command `python3` Note that since this example uses `*-minimal` image as the base image and added only few packages for SSH connection and debugging, there should be still missing packages and modules for some modules and collections. @@ -119,13 +122,13 @@ Ansible Builder is building your execution environment image. Tags: registry.exa Running command: docker build -f context/Dockerfile -t registry.example.com/ansible/ee:2.15-custom context Sending build context to Docker daemon 50.18kB -Step 1/76 : ARG EE_BASE_IMAGE="quay.io/centos/centos:stream9-minimal" +Step 1/77 : ARG EE_BASE_IMAGE="quay.io/centos/centos:stream9-minimal" ... -Step 76/76 : CMD ["bash"] - ---> Running in a7dd36359206 -Removing intermediate container a7dd36359206 - ---> db146c87502d -Successfully built db146c87502d +Step 77/77 : CMD ["bash"] + ---> Running in 2eff2dca84d2 +Removing intermediate container 2eff2dca84d2 + ---> d804667597e9 +Successfully built d804667597e9 Successfully tagged registry.example.com/ansible/ee:2.15-custom Complete! The build context can be found at: /home/********/awx-on-k3s/builder/context @@ -136,7 +139,7 @@ Once the command is complete, your custom EE image is built and stored on Docker ```bash $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE -registry.example.com/ansible/ee 2.15-custom db146c87502d 20 seconds ago 281MB +registry.example.com/ansible/ee 2.15-custom d804667597e9 20 seconds ago 284MB ``` ## Use EE @@ -155,7 +158,7 @@ Simply you can push your EE image to some container registry. Any registry can b $ docker push registry.example.com/ansible/ee:2.15-custom The push refers to repository [registry.example.com/ansible/ee] ... -2.15-custom: digest: sha256:bf799b01b32bccb2570911ae77e3700ef9cc5d708699a9fa421124c038a57d31 size: 3452 +2.15-custom: digest: sha256:193b380672c64768231973c58a154fb8eec0f0aae1891e63aea3918308a06716 size: 3456 ``` Then you can specify `registry.example.com/ansible/ee:2.15-custom` as your own custom EE in AWX. Specify registry credentials if your container registry requires authentication. @@ -182,7 +185,7 @@ Ensure your imported image is listed. $ sudo /usr/local/bin/k3s crictl images IMAGE TAG IMAGE ID SIZE ... -registry.example.com/ansible/ee 2.15-custom db146c87502d4 96.3MB +registry.example.com/ansible/ee 2.15-custom d804667597e9e 96.3MB ... ``` diff --git a/builder/execution-environment.yml b/builder/execution-environment.yml index e21331e..70e6139 100644 --- a/builder/execution-environment.yml +++ b/builder/execution-environment.yml @@ -1,6 +1,6 @@ --- # Refer to Ansible Builder Documentation for details for each options: -# https://ansible-builder.readthedocs.io/en/stable/definition/ +# https://ansible.readthedocs.io/projects/builder/en/latest/definition/ version: 3 @@ -31,9 +31,9 @@ dependencies: package_pip: ansible-core~=2.15 ansible_runner: package_pip: ansible-runner~=2.3 - galaxy: dependencies/requirements.yml - python: dependencies/requirements.txt system: dependencies/bindep.txt + python: dependencies/requirements.txt + galaxy: dependencies/requirements.yml additional_build_files: - src: files/ansible.cfg @@ -45,8 +45,9 @@ additional_build_steps: append_base: # - RUN echo "Additional steps for append_base" - RUN alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 0 - # prepend_galaxy: - # - RUN echo "Additional steps for prepend_galaxy" + prepend_galaxy: + # - RUN echo "Additional steps for prepend_galaxy" + - ADD _build/configs/ansible.cfg ~/.ansible.cfg # append_galaxy: # - RUN echo "Additional steps for append_galaxy" # prepend_builder: diff --git a/builder/files/ansible.cfg b/builder/files/ansible.cfg index 14c8065..846b37d 100644 --- a/builder/files/ansible.cfg +++ b/builder/files/ansible.cfg @@ -1,2 +1,5 @@ -[defaults] -host_key_checking = False +[galaxy] +server_list = public + +[galaxy_server.public] +url = https://galaxy.ansible.com/