Execution Environments

Last updated: January 12, 2026

📚 Reference: This guide aligns with the official Getting started with Execution Environmentsarrow-up-right documentation.

My Journey to Execution Environments

After years of managing Ansible across different teams and environments, I've encountered a recurring challenge: dependency hell. One team needs Python 3.8 with specific libraries, another needs Python 3.11, and a third team requires completely different collections and modules. Managing these dependencies on a shared control node was becoming a nightmare. That's when I discovered Execution Environments (EEs) – and it transformed how I approach Ansible automation.

What Are Execution Environments?

Execution Environments are container images that serve as Ansible control nodes. Think of them as self-contained, portable automation units that include:

  • Ansible Core or Ansible

  • Ansible Collections and their dependencies

  • Python packages required by modules

  • System packages needed for specific tasks

  • Custom plugins and modules

Instead of installing dependencies directly on your control node, you package everything into a container image that can be shared, versioned, and run consistently anywhere.

Why Use Execution Environments?

From my experience, here are the compelling reasons to adopt EEs:

1. Dependency Isolation

Different automation projects can have completely different requirements without conflict. One EE can use Ansible 2.15 with specific collections, while another uses Ansible 2.17 with different dependencies.

2. Consistency Across Environments

The same container that works on your laptop will work in CI/CD pipelines, on your colleague's machine, and in production automation platforms. No more "works on my machine" issues.

3. Version Control for Dependencies

Your entire automation stack – Ansible version, collections, Python libraries – is versioned as a container image. You can roll back to previous versions if needed.

4. Simplified Onboarding

New team members just pull the EE container image and start running playbooks. No lengthy setup process or dependency installation.

5. Security and Compliance

Scan container images for vulnerabilities, ensure only approved dependencies are used, and maintain a clear audit trail of what's running where.

6. Cloud-Native Integration

EEs work seamlessly with Kubernetes, OpenShift, and other container orchestration platforms.

Understanding the Architecture

Here's how Execution Environments fit into the Ansible ecosystem:

spinner

Getting Started with Execution Environments

Prerequisites

Install the required tools:

Creating Your First Execution Environment

Step 1: Define Your Requirements

Create an execution-environment.yml file:

Step 2: Define Collection Requirements

Create requirements.yml:

Step 3: Define Python Dependencies

Create requirements.txt:

Step 4: Define System Dependencies

Create bindep.txt:

Step 5: Build Your Execution Environment

Step 6: Test Your Execution Environment

Real-World Example: Multi-Cloud Automation EE

Here's a practical example for an organization managing AWS, Azure, and on-premise infrastructure:

execution-environment.yml

requirements.yml

requirements.txt

Using ansible-navigator

ansible-navigator is the modern CLI for running playbooks with EEs. Here's how I use it:

Basic Playbook Execution

Configuration File

Create ansible-navigator.yml to avoid repeating parameters:

Now you can simply run:

Managing Execution Environment Images

Best Practices for EE Management

1. Version Your Images

2. Use a Container Registry

3. Scan for Vulnerabilities

4. Keep Images Lean

Advanced Patterns

Multi-Stage Builds

For complex EEs, use multi-stage builds to keep the final image small:

Custom Base Images

Create a custom base image for your organization:

Then use it in your EE:

Environment-Specific EEs

Build different EEs for different purposes:

Integration with CI/CD

GitLab CI Example

GitHub Actions Example

Troubleshooting Common Issues

Issue 1: Image Build Fails

Issue 2: Collections Not Found

Issue 3: Python Dependencies Missing

Issue 4: SSH Key Access

When using SSH keys with EEs:

Or configure in ansible-navigator.yml:

Migration from Traditional Ansible

Gradual Migration Strategy

  1. Start with a Base EE: Use an official EE as-is

  2. Add Collections Incrementally: Add your collections one at a time

  3. Test Thoroughly: Verify all playbooks work in the EE

  4. Document Dependencies: Record what each playbook needs

  5. Optimize: Remove unused dependencies

Migration Checklist

Best Practices Summary

From my experience deploying EEs across multiple organizations:

  1. Keep Images Small: Only include what you need

  2. Version Everything: Tag images with semantic versions

  3. Use Private Registries: For organizational EEs

  4. Scan for Vulnerabilities: Make it part of your build process

  5. Document Requirements: Clear execution-environment.yml files

  6. Test Before Pushing: Verify EEs work before sharing

  7. Pin Versions: Use specific versions in production

  8. Automate Builds: Build EEs in CI/CD pipelines

  9. Monitor Image Sizes: Keep track of bloat

  10. Regular Updates: Keep base images and dependencies current

Conclusion

Execution Environments represent a significant evolution in how we run Ansible automation. They solve real problems around dependency management, consistency, and portability. While there's a learning curve, the benefits – especially in team environments and CI/CD pipelines – make EEs essential for modern Ansible usage.

Whether you're managing a small team or enterprise-scale automation, EEs will help you deliver more reliable, consistent automation with less friction.


Further Reading

Ready to containerize your automation? Start building your first Execution Environment today! 🐳

Last updated