mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-03 23:01:48 +00:00
Add inventory plugins for buildah and podman, unit tests and functional CI tests. --------- Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com> |
||
|---|---|---|
| .. | ||
| go_app | ||
| model_server | ||
| node_app | ||
| roles/ai-dev-env/tasks | ||
| build_ai_env_with_ansible.yml | ||
| build_go_ai_multistage.yml | ||
| build_node_ai_api.yml | ||
| README.md | ||
Buildah connection playbook examples
This folder contains self-contained Ansible playbooks demonstrating how to build images with Buildah while executing steps inside a working container through the Buildah connection plugin (ansible_connection: containers.podman.buildah). Each example shows a realistic workflow and explains the options used.
Prerequisites
- Podman and Buildah installed (rootless supported)
- Ansible installed (
ansible-corerecommended) - Network access to pull base images
How these playbooks work
- A working container is created on localhost using
buildah from <image>. - The playbook dynamically adds a temporary inventory host whose
ansible_connectioniscontainers.podman.buildahandremote_addris the Buildah working container ID. - File operations and commands within the container use the Buildah connection plugin (no SSH), so modules like
copy,command, andshellact inside the container. - Image metadata/commit/push operations are executed on localhost with
buildah config/commit/pushreferencing the same container ID.
Common variables
buildah_base_image: base image to start the working container (varies per example)image_name: final image name (and optional tag)ansible_buildah_working_directory: working directory inside the container for all build steps (passed to the connection plugin)
Examples
-
build_node_ai_api.yml — Node.js AI prediction API image without a Dockerfile
- Starts from
node:14, copiespackage.jsonand app sources to/app, runsnpm install, sets image metadata, commits tomy-ai-node-app:latest. - Options highlighted:
ansible_connection: containers.podman.buildahansible_buildah_working_directory: /app
- Starts from
-
build_go_ai_multistage.yml — Multi-stage Go build to a minimal runtime image
- Stage 1: compile inside
golang:1.21working container, fetch the compiled binary to host. - Stage 2: start
alpine:latest, copy binary into the container, configure CMD and exposed port, commitminimal-ai-inference:latest. - Shows how to move artifacts between stages using the connection plugin’s
fetch_fileand normalcopy.
- Stage 1: compile inside
-
build_ai_env_with_ansible.yml — Create a consistent AI dev environment image with an Ansible role
- Starts from
python:3.11-slim, then applies roleroles/ai-dev-envwhich installs common data-science packages inside the container using raw/pip commands. - Demonstrates layering higher-level Ansible logic on top of a Buildah working container.
- Starts from
-
gitlab_ci_build_model_image.yml — CI-friendly image build using Buildah connection (template)
- Builds and optionally pushes an image for a simple model serving app (
app.py,requirements.txt). - Designed to be called from GitLab CI; see the included
.gitlab-ci.ymlfor a minimal job that runsansible-playbook.
- Builds and optionally pushes an image for a simple model serving app (
Running an example
cd playbook/examples
ansible-playbook build_node_ai_api.yml -e image_name=my-ai-node-app:latest
Notes
- The Buildah connection runs commands with
buildah run <container> …under the hood; metadata operations such asbuildah config,commit, andpushstill run on localhost and reference the working container ID. - If you prefer persistent names, set
container_name(Buildah will use named working containers). Otherwise, the container ID returned bybuildah fromis used.