Ansible Pilot

Publishing Ansible Collections to Ansible Galaxy and Automation Hub

How to distribute our custom Ansible Collection to Ansible Galaxy and Automation Hub.

November 18, 2023
Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons

Introduction

Ansible Collections provides a structured way to package and distribute Ansible content, offering a modular and organized approach to automation. Collections typically include modules, plugins, roles, and playbooks that address specific use cases. In this article, we’ll delve into the process of distributing Ansible Collections, covering key aspects such as configuring distribution servers, building tarballs, and publishing collections.

Distribution Servers

Before distributing an Ansible Collection, you need to choose a distribution server. The prominent options include:

  1. Ansible Galaxy: Supports all collections and is widely used for community-driven content.
  2. Pulp 3 Galaxy: Similar to Ansible Galaxy but with added support for signed collections.
  3. Red Hat Automation Hub: Specifically for Red Hat-certified collections, with support for signed collections.
  4. Privately Hosted Automation Hub: Enables distribution of collections authorized by the owners.

Distribution Process Overview

Distributing an Ansible Collection involves several steps:

  1. Initial Configuration of Distribution Servers:
  1. Building the Collection Tarball:
  1. Preparing to Publish:
  1. Publishing the Collection:

Initial Configuration of Distribution Servers

Creating a Namespace

Create a namespace on each distribution server. Note that Ansible Galaxy namespaces cannot include hyphens.

Getting Your API Token

Obtain a separate API token for each distribution server. Retrieve the token from the respective server, such as the Galaxy profile preferences page.

Specifying Your API Token and Distribution Server

Specify the API token and distribution server either in the ansible.cfg file or by passing them as arguments to the ansible-galaxy command. Configuring in the ansible.cfg file is more secure.

[galaxy]
server_list = ansible_galaxy

[galaxy_server.ansible_galaxy]
url=https://galaxy.ansible.com/
token=abcdefghijklmnopqrtuvwxyz

Building the Collection Tarball

After configuring distribution servers, build a collection tarball using the ansible-galaxy collection build command. Ensure you review and update the version number in the galaxy.yml file.

Ignoring Files and Folders

Exclude unnecessary files using the build_ignore key in the galaxy.yml file or leverage manifest directives for more control over exclusion patterns.

Signing a Collection

For Pulp 3 Galaxy servers, consider including a GnuPG signature with your collection for added security.

ansible-galaxy collection build
tar -Oxzf namespace-name-1.0.0.tar.gz MANIFEST.json | gpg --output namespace-name-1.0.0.asc --detach-sign --armor --local-user [email protected] -

Preparing to Publish Your Collection

Before publishing, install the collection locally, review it for issues, and ensure the version number is correctly incremented following semantic versioning.

The Best Resources For Ansible

Certifications

Video Course

Printed Book

eBooks

Publishing Your Collection

Publishing can be done either from the command line using ansible-galaxy collection publish or directly on the distribution server’s website.

Command Line Publishing

Execute ansible-galaxy collection publish with the path to the collection tarball. Ensure your API token is correctly configured.

Website Publishing

On the distribution server’s website, navigate to the upload section and select the collection tarball. This triggers an import process, and you can monitor the progress on the My Imports page.

Conclusion

Distributing Ansible Collections involves careful configuration, versioning, and adherence to best practices. Whether using popular platforms like Ansible Galaxy or Red Hat Automation Hub, understanding the process ensures seamless sharing and consumption of Ansible automation content.

Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Access the Complete Video Course and Learn Quick Ansible by 200+ Practical Lessons
Follow me

Subscribe not to miss any new releases