Technology / DevOps

5 Ways to Streamline Automation Using Ansible Galaxy

5 Ways to Streamline Automation Using Ansible Galaxy picture: A
Follow us
Published on August 2, 2022

Ansible Galaxy is a website that allows communities to share and publish Ansible Roles. This free-to-use web page is a boon to streamlining automation. Its corresponding UI makes it easy to download and upload Ansible roles. So let's discuss five ways the website and its corresponding CLI can be used to streamline your automation process. First though, it would be worthwhile to discuss what an Ansible Role is.

Need to Learn Ansible?

You might be wondering what Ansible is. No worries. If you are new to DevOps and Ansible, you’ll find the training you need to get up to speed at CBT Nuggets. Learn how to leverage this open-source configuration management tool that is also great for deployments and automation. We offer several Ansible-related courses designed to help learners harness the power of Ansible. Start training on Ansible today!

What is an Ansible Role?

Ansible Roles are a convenient way for developers to share Ansible code. The core of Ansible is the Ansible Playbook. It holds numerous steps needed to configure multiple servers, deploy applications, allocate memory, etc. However, between teams a lot of these steps are the exact same. So instead of every team implementing the same steps, they just implement the same role.

For example, there may be three teams: One team runs Ubuntu, the other MacOS, and the last one Windows. They all have different playbooks, yet all need a Tomcat Server installed. Instead of repeating the same steps, they just leverage the same role. In fact, here is that very role on the galaxy website. Speaking of Galaxy, let's discuss five ways it can streamline automation.

1. Use the Git Module

I doubt there is a developer in the world who doesn't use Git — or at least has heard of Git. Git is a version control system that allows developers to share and keep track of code. This code is pulled down and used by other developers. However, with Ansible Galaxy, that code can be pulled down and used by Ansible as well.

The Git Modules allows users to deploy files or software directly from their Ansible Playbook. This can then be stored in a role using Ansible galaxy. Now all developers are pulling from the same, version controlled repository. This adds accountability and removes redundancy. However, this is especially useful when you create your own roles. Let's look at that next.

2. Create Roles

Roles are the crux of Ansible Galaxy. A developer can create their own role by using the Ansible Galaxy CLI. Specifically, the command is ansible-galaxy init. This will create the directory Ansible requires for role creation.

Often developers need to do this when a list of steps must be duplicated around the organization. Then these roles can be checked into a code repository and then checked out via the aforementioned Git module.

Additionally, the collection can be uploaded to Ansible Galaxy for others to use. Sometimes creating your own role may not be needed. The very steps you're looking for could very well be on the Ansible Galaxy website.

3. Pull Roles, Modules, and Playbooks from Ansible Galaxy

It is often said in software engineering to never reinvent the wheel. With the advent of Ansible Galaxy that should never be a problem. Before creating your own Ansible utility, it is recommended to first check if a similar role or collection exists on Ansible galaxy. By using an existing collection, it will save your DevOps team a lot of development time.

Navigate to the search page and check if what you are looking for it here. With several hundreds collections, it's a good bet you will find something to assist your organization.

4. Group Parameters by Operating System

Ansible playbooks often need to be executed on different operating systems. Unfortunately, this can lead to a lot of pitfalls or unclear playbooks. After all, Ansible roles are supposed to be used by a wide variety of teams — so automation can be greatly hindered by different OS environments. In order to streamline automation, it is highly recommended that the group_by module is utilized in your playbook. Here is a quick example:

- group_by:

    key: machine_{{ my_machine }}
# Create groups like ‘aws_ubuntu_vm'
- group_by:
    key: aws_{{ ubuntu_virtualization_type }}_{{ ubuntu_role }}
# Create nested groups
- group_by:
    key: el{{ ubnuntu_version}}-{{ ubuntu_architecture }}
    parents:
      - el{{ ubuntu_version }}

In the above example, we are providing specific deployment instructions based off the operating system used.

5. Familiarize Yourself with Ansible-Galaxy CLI

One of the most important aspects of Ansible-Galaxy is its CLI (Command Line Interface.) The CLI allows the user to perform actions on roles and collections located within Ansible-Galaxy. For example, Ansible-Galaxy init <namespace>.<collection> will create a new role and the skeleton file structure.

The CLI also allows users to remove, delete, install, and publish roles to Ansible-Galaxy. It is also important to use the ansible.cfg file. It stores environment specific variables such as the operating system being used, specific IP addresses, user names, and more. Ultimately, having a deep understanding of Ansible-Galaxy CLI will assist in troubleshooting and automating your development process.

Final Thoughts

In this article we discussed five ways to streamline your automation using Ansible Galaxy. First, integrate your Ansible deployments with Git. Next create roles using the ansible-galaxy CLI. It is also a great idea to search the Ansible Galaxy website to see if a similar role or collection already exists.

To make deployments run smoother, group different operating system variables together in the Ansible file. This will reduce build error and decrease time spent troubleshooting. Lastly, have a deep understanding of the Ansible-Galaxy CLI. It will allow you to quickly create, download, or publish roles needed to automate your build pipeline. Ansible Galaxy has a vibrant community and a multitude of uses. Even a cursory look at Ansible-Galaxy proves it has a lot to offer.


Download

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.


Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522