0%

0/1 Lessons

Course Introduction

• 19min

0 / 2 lessons complete

IT Lab Setup

• 31min

0 / 3 lessons complete

Installing Ansible

• 57min

0 / 4 lessons complete

Managing your Ansible Inventory

• 2hr 45min

0 / 8 lessons complete

Ansible Basics

• 2hr 55min

0 / 9 lessons complete

Ansible Roles

• 2hr 40min

0 / 8 lessons complete

Ansible Galaxy

• 2hr 42min

0 / 6 lessons complete

Ansible Facts, Variables, Passwords and Templates

• 3hr 23min

0 / 9 lessons complete

Advanced Ansible Playbook Creation

• 2hr 39min

0 / 8 lessons complete

Course Conclusion

• 11min

0 / 1 lessons complete

Installing Roles from Ansible Galaxy

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, you will learn about Ansible Galaxy, a hub for finding and sharing Ansible content. By the end of this lesson, you will know how to navigate the Ansible Galaxy website to find collections and roles, use the ansible-galaxy search command to find roles for installation, and how to install a role using the ansible-galaxy install command. We'll also integrate the Docker role by Geerlingguy into your playbook.

What is Ansible Galaxy?

Ansible Galaxy is essentially a large public repository for Ansible roles and collections. These roles and collections are pre-written codes by the community that can be used to automate a wide range of tasks. By using roles from Ansible Galaxy, you can leverage the expertise of others to streamline your automation tasks.

Using the Ansible Galaxy Website

The Ansible Galaxy website (https://galaxy.ansible.com/) is a user-friendly interface where you can search and explore thousands of roles and collections.

Ansible Galaxy Official Website
Ansible Galaxy Official Website

On this website, you can filter your search by categories, such as cloud, system, monitoring, and so on. Each role and collection comes with documentation, including how to install and use it, making your job much easier.

Try searching for the role docker, then sort by Download count:

Searching Ansible Galaxy Roles for Docker
Searching Ansible Galaxy Roles for Docker

I like to search by download count to get the most popular items listed first. If we click on the first result, we can see the command we would use to install this role:

Installing Roles from Ansible Galaxy's Website
Installing Roles from Ansible Galaxy's Website

There is a copy button next to the installation command that allows for quick and easy installation of the role, which we won't do just yet because I want to show you how to use the search command to find content on Ansible Galaxy.

Searching with ansible-galaxy search

Sometimes, you might want to search for roles directly from your command line. This is where the ansible-galaxy search command comes in handy. To search for a specific role or keyword, you use:

ansible-galaxy search keyword

For example, to search for Docker-related roles, you would use:

ansible-galaxy search docker

This command will list all the roles related to Docker, along with their author and description.

Installing Roles with ansible-galaxy install

Once you find a role you want to use, the next step is to install it. This is done using the ansible-galaxy install command. Let's take the popular 'geerlingguy.docker' role as an example. To install this role, you would run:

paulh@ansible-controller:~$ ansible-galaxy install geerlingguy.docker
Starting galaxy role install process
- downloading role 'docker', owned by geerlingguy
- downloading role from https://github.com/geerlingguy/ansible-role-docker/archive/7.0.2.tar.gz
- extracting geerlingguy.docker to /home/paulh/.ansible/roles/geerlingguy.docker
- geerlingguy.docker (7.0.2) was installed successfully

This command downloads the Docker role from Ansible Galaxy and makes it available for use in your playbooks.

Default Installation Directory

When you install a role using Ansible Galaxy, it places the role in a directory designated for Ansible roles. The default location depends on your system and Ansible configuration. Typically, these are the common directories:

In this case, the role is installed into my users home directory at /home/paulh/.ansible/roles/geerlingguy.docker. We can list our installed Ansible Galaxy roles like so:

paulh@ansible-controller:~$ ansible-galaxy list
# /home/paulh/.ansible/roles
- geerlingguy.docker, 7.0.2
# /etc/ansible/roles
[WARNING]: - the configured path /usr/share/ansible/roles does not exist.

Adding the Role to a Playbook

After installing the role, the next step is to add it to your playbook. Let's use first_playbook.yml as an example. Edit this file with your preferred text editor:

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments