Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Publishing Roles to Galaxy - Ansible Tutorial

Introduction

Ansible Galaxy is a repository for Ansible roles. It allows users to share and download roles, making it easier to reuse code for common tasks. In this tutorial, we will walk through the process of publishing roles to Galaxy from start to finish.

Prerequisites

Before you can publish a role to Galaxy, you need to have the following:

  • An Ansible role that you want to share.
  • A GitHub account to host your role's repository.
  • An account on Ansible Galaxy.

Step 1: Prepare Your Role

Ensure your role follows the standard directory structure and includes all necessary files like meta/main.yml and README.md. Here's an example structure:

my_role/
├── README.md
├── defaults/
│   └── main.yml
├── handlers/
│   └── main.yml
├── meta/
│   └── main.yml
├── tasks/
│   └── main.yml
├── templates/
└── vars/
    └── main.yml
                

Step 2: Create a GitHub Repository

Create a new repository on GitHub for your role. The repository name should match the role name. For example, if your role is named my_role, the repository should also be named my_role.

Initialize the repository with a README file and push your role's files to this repository.

Step 3: Login to Ansible Galaxy

Log in to Ansible Galaxy using your GitHub credentials:

ansible-galaxy login

Step 4: Link Your GitHub Repository

Link your GitHub repository to your Ansible Galaxy account. This allows Galaxy to access your role's repository:

ansible-galaxy import <GitHub username> <repository name>

For example:

ansible-galaxy import johndoe my_role

Step 5: Publish Your Role

Once your repository is linked, you can publish your role to Galaxy. Navigate to the "My Roles" page on Galaxy and click the "New Role" button.

Fill out the required information, such as the GitHub repository URL, and click "Create Role". Galaxy will import your role and make it available for others to download.

Step 6: Update Your Role

To update your role after making changes, push the changes to your GitHub repository and re-import the role to Galaxy:

ansible-galaxy import <GitHub username> <repository name>

Conclusion

Publishing roles to Ansible Galaxy is a straightforward process that enables you to share your roles with the community. By following the steps outlined in this tutorial, you can easily publish and maintain your roles on Galaxy.