Site icon techbeatly

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:

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:

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:

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!

Exit mobile version