Get up to 50% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

Where Should You Keep Your Ansible Collection?

Where Should You Keep Your Ansible Collection?

Simplifying Automation with Organized Collections

Introduction

Ansible Content Collections revolutionize automation content management by offering a simplified, consistent, and portable way to deliver modules, roles, and playbooks. Their versioning and reusability enable better collaboration and seamless integration into various workflows.

But where should you store your Ansible Collections? The answer depends on your specific use case. Let’s explore the options.

What Are Content Collections?

Ansible Content Collections bundle automation content like modules, roles, and playbooks into portable, reusable, and versioned packages. These Collections:

  • Simplify content delivery.
  • Promote collaboration.
  • Enhance portability across systems and environments.

Where Can Collections Exist?

1. In Execution Environments

Execution Environments (EEs) are container images that package all dependencies, including Ansible Collections, plugins, and Python libraries, into a consistent runtime.

To create or customize an EE, use the ansible-builder tool to define the necessary dependencies and build the container image. Collections included in the EE are automatically available wherever the container runs.

This is the most robust method, especially for environments managed via the Red Hat Ansible Automation Platform.

2. In a System Path

You can store Collections in a directory on the system and configure the ansible.cfg file to point to it.

Example ansible.cfg :

COLLECTIONS_PATHS = ./collections:~/.ansible/collections:/usr/share/ansible/collections

Caution: This approach is less suited for multi-node setups, such as Red Hat Ansible Automation Platform, as mounting local directories across multiple execution nodes is challenging.

3. In the Playbook Path

Collections can also reside alongside the playbook in a dedicated collections directory.

Steps:

  1. Create a collections directory in the same folder as your playbook.
  2. Update the ansible.cfg file:
...
COLLECTIONS_PATHS = ./collections:~/.ansible/collections:/usr/share/ansible/collections
...

This approach ensures collections travel with your playbook, simplifying portability and reducing dependency concerns.

4. Defined in requirements.yml

For larger or distributed setups, define Collections in a requirements.yml file and let Ansible fetch them from a source such as:

  • Ansible Galaxy
  • Private Automation Hub
  • Git repositories

Example requirements.yml :

collections:
  - name: https://github.com/iamgini/ansible-collections-in-git-demo.git#/azure-azcollection-1.18.1/
    type: git
  - name: https://github.com/iamgini/ansible-collections-in-git-demo.git#/community-general-7.4.0/
    type: git
  - name: cisco.ios
    version: 5.2.0
    source: https://galaxy.ansible.com
  - name: amazon.aws
    version: 6.5.0
    source: https://aap.example.local/api/galaxy/content/rh-certified/

The requirements.yml method is highly recommended for automation environments as it integrates seamlessly with automation controllers.

5. Hybrid Approaches

It’s possible to combine methods to suit your needs. For instance:

  • Use private Collections locally while fetching others from Ansible Galaxy.
  • Mix Execution Environments with playbook-specific Collections for better flexibility.

Ensure the COLLECTIONS_PATHS variable is updated to reflect your hybrid setup.

Conclusion

Choosing the right location for your Ansible Collections depends on your workflow and infrastructure. Whether you use Execution Environments for streamlined containerized automation or manage Collections alongside your playbooks for portability, proper organization ensures a smoother automation experience.

Where do you keep your Ansible Collections? Let us know in the comments!

Share :

Related Posts

Integrating Ansible Automation Platform with CyberArk Password Vault to retrieve credentials

Integrating Ansible Automation Platform with CyberArk Password Vault to retrieve credentials

Introduction Integrating the Ansible Automation Platform with CyberArk allows you to retrieve credentials securely and automatically from CyberArk’s …

Learn Ansible – A Comprehensive Guide for Courses and Exams

Learn Ansible – A Comprehensive Guide for Courses and Exams

Introduction Ansible is a well-known open-source IT and application automation software which can be used to implement enterprise automation use …

Running PostgreSQL Instances as Containers with Podman

Running PostgreSQL Instances as Containers with Podman

PostgreSQL is a powerful, open-source relational database system widely used in modern applications. Running PostgreSQL as a container offers a range …

Multi-Level Approvals in Ansible Automation Controller: A Workaround

Multi-Level Approvals in Ansible Automation Controller: A Workaround

Ansible Automation Controller streamlines IT tasks through automation. A key component of this power lies in workflows . These workflows allow you to …

Ansible Navigator Cheat Sheet

Ansible Navigator Cheat Sheet

What is ansible-navigator ansible-navigator is the new command line utility (CLI) introduced in Ansible Automation Platform 2, for running and …