- What is Ansible Galaxy? - Fri, Oct 14 2022
- Pushing and popping: Navigating in PowerShell with Push-Location and Pop-Location - Wed, Mar 3 2021
Ansible Galaxy enables you to discover new roles or collections quickly and easily to help you deploy infrastructure and applications faster. I'll also show you how you can share your own roles and collections with others in the Ansible community.
How to use Ansible Galaxy
Ansible comes out of the box with a core set of modules that handle most basic system configuration needs. However, there's much more that Ansible can configure through the use of roles and collections.
Imagine, for a moment, that you need to automate the configuration of the firewall on an Ubuntu server. You have some familiarity with Ansible and would like to build a playbook to accomplish this task. You just don't know where to start.
Here's where Ansible Galaxy comes in.
Discovering roles and collections
It's best to begin by heading over to the Ansible Galaxy search page. From the search page, you can apply and combine filters to help narrow the terms you are searching for. You can also adjust the results to further enhance your search. From the search page, you have access to both partner and community content.
Recall that you need to configure the firewall on a new Linux server using ufw. Let's walk through how to discover some community-provided roles and collections that can help accomplish your goal.
Start by clicking Search in the left menu on the Ansible Galaxy home page.
Next, type in a search term for the role or collection you need. For this example, you are searching for "UFW." You may also choose to apply filters, but let's keep things simple for now. Click the magnifying glass to search or press the Enter key.
Notice that the results return both Collections and Roles.
UFW search results
From here, you can inspect some of the collections and roles a bit further and read their installation instructions and code examples.
Installing roles and collections
Now that you have found a suitable role, it's time to make the role or collection available to Ansible by installing it. To do so, follow these steps:
Assuming you already have Ansible installed and have an internet connection on your host, you can install the module using the installation instructions provided in the role contributor's documentation, as shown below:
Ansible-galaxy install markahesketh.ufw
From here, you can begin writing Ansible playbooks that use the UFW role you downloaded to configure UFW for a Linux host.
Note: Ansible comes with many built-in community modules and roles out of the box. For example, you could use community.general.ufw to manage the UFW firewall settings instead of downloading them from Ansible Galaxy.
You can repeat the steps above for other roles or collections that you may find interesting. Always be sure to read over the provided documentation to fully understand how the role or collection is used, as not all will contain the options you may need.
You can read more about installing roles and collections in the Ansible Galaxy Documentation.
But what if you have written a role that contains every option a SysAdmin would need for a task? Glad you asked. Keep reading!
How to contribute to Ansible Galaxy
Contributors are what make Ansible Galaxy a great online community that shares reusable automation content. There are a few guidelines for contributing to Ansible Galaxy that you should follow when considering releasing your creation for community consumption. Here's what you need to do to get started.
Join the community
Joining the Ansible Galaxy community is as simple as linking an existing GitHub account.
Start by clicking Login in the top ribbon menu.
Next, click the GitHub logo to begin linking your account with Ansible Galaxy. (You can sign up for a free GitHub account if you do not already have one.)
Now authorize Ansible Galaxy to have read-only permission to your GitHub profile.
Once linked, you will see two additional menu items on the left nav bar.
And that's it! Now that your account has been created and linked to a GitHub profile, all you have to do now is share the repository that contains your Ansible role or collection.
Sharing your creations
Let's assume you have already created a role that is available in a GitHub repository. To share this role, you must add it from either your GitHub repository or by uploading a collection.
Once you've imported your role or collection, you'll be able to search for the namespace and share the link to your contribution with the rest of the world!
Subscribe to 4sysops newsletter!
The Ansible Community is where it's at today because of current and future contributors like you. This is just one aspect of what you can do with Ansible Galaxy. If you are interested in other ways to contribute, check out the How can I help? documentation. You can also simply answer online questions through some of the official channels.
Want to write for 4sysops? We are looking for new authors.