Interview Prep/Ansible/Architecture Decisions and Tool Comparisons

Should you use Ansible to build container images?

IntermediateProductionArchitecture Decisions and Tool Comparisons
Answer

Usually not. A Dockerfile or Containerfile gives layer caching, reproducible builds and tooling everyone understands. Running a playbook inside an image build produces big, uncached layers, needs Python in the image and hides what is installed.

Where Ansible does fit around containers:

  • Installing and configuring Docker, Podman or containerd on hosts.
  • Deploying and updating containers on plain VMs with community.docker.docker_container or containers.podman.podman_container, or with Quadlet units.
  • Building images through community.docker.docker_image as part of a larger workflow, which still uses the Dockerfile.

Execution environments are the exception: ansible-builder generates a Containerfile for you, which is the right way to build those.

All Ansible questions Roadmap: Ansible

More on Architecture Decisions and Tool Comparisons