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:
- Create a namespace on each distribution server.
- Obtain an API token for each server.
- Specify the API token and distribution server in the configuration.
2. Building the Collection Tarball:
- Review and update the version number in the
galaxy.ymlfile.
- Use the
ansible-galaxy collection buildcommand to create a tarball of the collection.
3. Preparing to Publish:
- Install the collection locally for testing.
- Review the collection for any issues.
- Understand and adhere to semantic versioning for your collection.
4. Publishing the Collection:
- Use either the command line (
ansible-galaxy collection publish) or the distribution server's website to upload and publish 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.
- API token for Galaxy, go to the Galaxy profile preferences (https://galaxy.ansible.com/me/preferences) page and click API Key.
- API token for Automation Hub, go to the token page (https://cloud.redhat.com/ansible/automation-hub/token/) and click Load token.
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.
``ini
[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 co