Skip to content

How to Utilize Ansible Collection from a Git Server with Ansible Automation Controller

Avatar photo

https://www.linkedin.com/in/gineesh/ https://twitter.com/GiniGangadharan

In the ever-evolving landscape of IT automation, Ansible has become a cornerstone for many organizations. One of the strengths of Ansible is its ability to modularize and distribute content using collections. These collections can include playbooks, roles, modules, and plugins, making it easier to manage and share automation tasks. Typically, you’d install and use collections through distribution servers like Ansible Galaxy or Pulp 3 Galaxy. However, in scenarios where enterprises operate in disconnected environments, accessing the internet, and external content repositories, can be challenging.

This is where Red Hat’s Ansible Automation Platform comes to the rescue, offering a Private Automation Hub. This in-house solution enables organizations to create and manage their own collections internally. But what if you prefer not to introduce a new tool into your environment and would rather keep things in-house using Git? Fortunately, the Ansible Automation Controller supports the ability to pull collections directly from your Git repositories. In this blog post, we’ll show you how to achieve this seamlessly.

A Glimpse into the Collections Repository

Before we dive into the technical details, let’s take a look at a sample collections repository structure. In our demo, we’ve organized collections into separate folders within the repository. Here’s what it looks like:

$ git remote -v
origin  [email protected]:iamgini/ansible-collections-in-git-demo.git (fetch)
origin  [email protected]:iamgini/ansible-collections-in-git-demo.git (push)

$ ls -l
total 12
drwxr-xr-x.  6 iamgini iamgini 4096 Sep 26 16:35 azure-azcollection-1.18.1
drwxr-xr-x. 11 iamgini iamgini 4096 Sep 26 17:39 community-general-7.4.0
-rw-r--r--.  1 iamgini iamgini   26 Sep 26 16:37 README.md

In this demo, there are two collections, each residing in a separate folder:

  1. azure-azcollection-1.18.1
  2. community-general-7.4.0

The structure is intuitive and easy to navigate, making it simple to manage your collections within your Git repository.

Configuring requirements.yaml in the Project Repository

The magic happens when you configure your requirements.yaml file in your playbook project repository. This is where you specify how the Ansible Automation Controller should fetch the collections. Take a look at this example:

$  cat collections/requirements.yml 
collections:
  - name: https://github.com/iamgini/ansible-collections-in-git-demo.git#/azure-azcollection-1.18.1/
    type: git
    # version: devel

  - name: https://github.com/iamgini/ansible-collections-in-git-demo.git#/community-general-7.4.0/
    type: git
    # version: devel

In this configuration:

  • type: git explicitly tells Ansible to fetch the collections from a Git repository.
  • The name field contains the Git URL, and the path to your specific collection within the Git repository is denoted by #/collection-path/.

With this setup, the Ansible Automation Controller knows where to look for your collections.

Creating a Project and Syncing

Now that your requirements.yaml file is properly configured, and you can create a project in Ansible Automation Controller. This project links to your playbook project repository. Once created, initiate a sync operation. During this process, the controller will reach out to your Git repository and pull in the collections based on the paths you defined.

Seeing it in Action

As a technical enthusiast, you’d love to see the magic happen. When you initiate the sync, you can actually visualize the controller pulling collections directly from your Git repository. Here’s a screenshot of what it looks like in action:

When I sync the project to fetch the latest playbooks, the controller will fetch the collection as well; see the highlighted area of screenshot.

If you want to see the details, we can check the logs by clicking on the specific tasks; for example the task “Fetch galaxy collections from collections/requirements.(yml/yaml)” here. The logs clearly explain that the collections were successfully fetched from another repo (our collection repo) and installed into the project directory (on the Automation controller) successfully. See the screenshot below for reference.

Note: Remember to add the Git credential if the repositories are private.

Wrapping it Up

In conclusion, utilizing Ansible collections from a Git server with an Ansible Automation Controller is a powerful way to manage your automation content, especially in disconnected environments. By simply configuring your requirements.yaml with the Git repository information and path to the collection, you can seamlessly integrate your Git-hosted collections into your automation workflows.

Happy automating!

Disclaimer:

The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.

Avatar photo


https://www.linkedin.com/in/gineesh/ https://twitter.com/GiniGangadharan
Gineesh Madapparambath is the founder of techbeatly and he is the author of the book - 𝗔𝗻𝘀𝗶𝗯𝗹𝗲 𝗳𝗼𝗿 𝗥𝗲𝗮𝗹-𝗟𝗶𝗳𝗲 𝗔𝘂𝘁𝗼𝗺𝗮𝘁𝗶𝗼𝗻. He has worked as a Systems Engineer, Automation Specialist, and content author. His primary focus is on Ansible Automation, Containerisation (OpenShift & Kubernetes), and Infrastructure as Code (Terraform). (aka Gini Gangadharan - iamgini.com)

Comments

1 Response

  1. […] inventory plugins required separate configuration files. However, in the Ansible automation controller, you can directly provide the new-style inventory plugin configuration through the source_vars field […]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.