Pre-built Images for Ansible
Pre-build a custom Ansible execution environment image with dependencies baked in for faster, reproducible pipeline runs.
Custom images pre-install dependencies in a Docker image, eliminating installation time on every pipeline run. Execution environments are containerized runtime environments for executing Ansible playbooks in Harness IaCM. By building custom images, you can package Ansible Core, Python dependencies, system packages, and Ansible collections into a reusable container that runs faster and provides consistent, reproducible builds across all pipeline executions.
Why build custom images
Custom execution environment images provide several benefits over installing dependencies at runtime:
Faster pipelines: Pre-install dependencies once instead of downloading them on every pipeline run.
Python packages pre-installed: Required by Ansible plugins, filters, and custom modules.
Ansible collections and roles bundled: Include collections in the image instead of downloading at runtime.
Include system packages: Add OS-level tools not in the base image, such as
sshpass,rsync, orjq.Reproducible builds: Lock dependency versions for consistent environments across development, testing, and production.
Isolation: Different projects can have different images with different dependencies.
Build a custom image
This example demonstrates adding the tabulate Python package to format data as tables. The formatting code runs inside the Ansible container and requires the tabulate package.
Create the Dockerfile
Create a Dockerfile that extends the Harness Ansible base image:
Build and push the image
Run the following commands to build, verify, and push your custom image:
Test the custom image locally (optional)
You can optionally test your custom image locally before using it in Harness to verify the package works correctly.
Create a test playbook
Create test-tabulate.yml with the following content:
Run the test with your custom image
Run the test playbook using your custom image:
Expected output
Verify it fails without the custom image
Confirm the package is required by testing with the base image:
Expected output
This confirms your custom execution environment is working correctly.
Use the custom image in Harness
After you verify your custom image works locally, reference it in your Harness pipeline.
Update your pipeline YAML
In your pipeline YAML, update the IACMAnsiblePlugin step to reference your custom image:
Make sure your playbook in the Harness workspace uses the tabulate package as shown in the test example.
Last updated
Was this helpful?