Skip to main content

Ansible Galaxy

Ansible Galaxy is a community-driven platform where you can find, share, and manage Ansible roles and collections. It’s a key resource for installing and managing reusable automation content, including the republic.crypto collection. This guide provides an overview of how to use Ansible Galaxy to install and manage collections and roles effectively.


1. What is Ansible Galaxy?​

Ansible Galaxy is a hub for sharing Ansible content. It hosts both roles and collections:

  • Roles: A set of tasks, templates, and handlers grouped together to accomplish specific functions.
  • Collections: A more structured and complete package that includes multiple roles, plugins, modules, and documentation.

Galaxy simplifies the process of finding, downloading, and managing this content, so you can easily reuse existing automation.


2. Ansible Collections vs Roles​

  • Roles: Traditionally, roles are reusable units of Ansible tasks, handlers, and other content.
  • Collections: A more advanced packaging system introduced in Ansible 2.9 that groups multiple roles, modules, and plugins into a single package.

The republic.crypto collection is an example of an Ansible collection that contains roles to manage blockchain infrastructure.


3. Installing Collections from Ansible Galaxy​

To install a collection, including republic.crypto, you use the ansible-galaxy command-line tool. For example, to install the republic.crypto collection:

ansible-galaxy collection install republic.crypto

This command pulls the latest version of the collection from Ansible Galaxy and installs it into your local environment. The content will be ready to use in your playbooks and roles.


4. Installing Specific Versions​

Ansible Galaxy allows you to specify the version of a collection or role to ensure compatibility with your playbooks.

Example: Installing a specific version of the republic.crypto collection:

ansible-galaxy collection install republic.crypto:1.0.0

This will install version 1.0.0 of the collection, ensuring that the correct version is used in your automation setup.


5. Managing Installed Collections​

You can list the installed collections in your environment using the following command:

ansible-galaxy collection list

This displays a list of all the collections currently installed, their versions, and where they are located.

If you need to update or remove a collection, you can use the following commands:

  • Update a collection:
ansible-galaxy collection install republic.crypto --force
  • Uninstall a collection:
ansible-galaxy collection uninstall republic.crypto

These commands help keep your environment clean and up-to-date with the latest automation content.


6. Using Collections in Playbooks​

Once installed, you can use the roles or modules from the collection in your playbooks. To reference a role from a collection, include it using its fully qualified name (FQCN):

Example Playbook:

---
- name: Setup CosmosHub node
hosts: all
roles:
- role: republic.crypto.cosmos

Here, the playbook uses the cosmos role from the republic.crypto collection, helping set up a CosmosHub blockchain node.


7. Using Galaxy to Search for Roles and Collections​

You can search for collections and roles on the Ansible Galaxy website or from the command line:

  • Web Search: Visit Ansible Galaxy and search for specific roles or collections.
  • Command Line:
ansible-galaxy collection search republic.crypto

This command searches for the republic.crypto collection or any other automation content related to your query.


8. Creating and Publishing Roles/Collections to Galaxy​

If you create your own role or collection, you can share it on Ansible Galaxy with the community. Follow these steps to publish content:

  1. Create a Role/Collection: Use ansible-galaxy init to scaffold a new role or collection.
  2. Build the Collection:
ansible-galaxy collection build
  1. Publish to Galaxy:
ansible-galaxy collection publish path/to/your-collection.tar.gz

You will need to have an account on Ansible Galaxy and be logged in using the ansible-galaxy login command.


9. Best Practices for Using Ansible Galaxy​

  • Pin Versions: When using collections or roles in production environments, always pin the version to avoid unexpected updates.
collections:
- name: republic.crypto
version: 1.0.0
  • Test Content: Before using third-party content from Galaxy, test it in a development environment to ensure it works as expected.
  • Keep Dependencies Up-to-Date: Regularly check for updates to the collections you rely on and apply updates when needed, ensuring compatibility with your playbooks.

Conclusion​

Ansible Galaxy is an essential resource for finding and managing reusable Ansible roles and collections, like republic.crypto. By leveraging Galaxy, you can simplify the process of managing complex infrastructure and reuse community-driven content to speed up automation development. Whether installing, updating, or creating your own collections, Galaxy provides a streamlined way to integrate Ansible content into your workflows.