Video Summary

Day-05 | Ansible Galaxy Tutorial | Write less code, Use existing roles from galaxy

Abhishek.Veeramalla

Main takeaways
01

Ansible Galaxy is a marketplace of reusable roles that save you from writing complex, OS-specific playbook logic.

02

Use the ansible-galaxy CLI to search, install, initialize, and manage roles; installed roles live in .ansible_roles.

03

Reference installed roles under the playbook's roles: section to apply tested tasks (demo: installing Docker).

04

Publish roles by storing them on GitHub, adding meta/docs, and importing into Galaxy using an API token.

05

Always review role documentation and repo tasks to ensure compatibility and trustworthiness before use.

Key moments
Questions answered

What is Ansible Galaxy and when should I use roles from it?

Ansible Galaxy is a marketplace of community-published roles. Use it when tasks (like installing Docker) must work across multiple OSes or when common automation already exists—this reduces custom code and conditional complexity.

How do I install a role from Ansible Galaxy?

Use the ansible-galaxy CLI (eg. ansible-galaxy install <role>); installed roles are placed in a local roles directory such as ~/.ansible_roles and can then be referenced in your playbook's roles section.

How can I publish my own role to Ansible Galaxy?

Push your role to a public GitHub repository, include proper meta and README documentation, then import it into Ansible Galaxy using your Galaxy account and API token so others can discover and reuse it.

How should I verify a Galaxy role before using it in production?

Review the role's README and GitHub repo, inspect its tasks and supported OS matrix, check download/popularity stats, and test the role on a representative environment before wide deployment.

Where do I reference an installed role inside an Ansible playbook?

Add the role name under the playbook's roles: section so Ansible applies the role's tasks when the play runs.

Recap of Previous Episodes 00:20

"In the first episode, we learned about the introduction to Ansible, the advantages of using Ansible for configuration management over shell scripting and Python scripting, and how to install and configure Ansible."

  • In the first four episodes of the Ansible series, viewers were introduced to the basics of Ansible, including its benefits for configuration management compared to shell and Python scripting.

  • Viewers also explored passwordless authentication, inventory management, and ad-hoc commands in Episode 2.

  • Episode 3 focused on YAML files and playbooks, culminating in writing a playbook to install a web server.

  • The fourth episode introduced Ansible roles, discussing their advantages such as modularity, flexibility, and readability.

Deep Dive into Ansible Galaxy 02:28

"In this episode, we will learn how to use existing Ansible roles from Ansible Galaxy, import them, install them, and publish our own roles."

  • The current episode is dedicated to Ansible Galaxy, a marketplace for Ansible roles where users can find and utilize existing roles to simplify their configuration management tasks.

  • Abhishek plans to demonstrate how to effectively write complex configurations using Ansible Galaxy’s existing roles, thus minimizing the need for custom code.

  • A live demonstration will show how to handle a task, such as installing Docker on various operating systems while leveraging Ansible Galaxy's existing roles.

Searching for and Using Roles 04:14

"In Ansible Galaxy, you have thousands of roles written and published by different DevOps engineers and system administrators."

  • The advantage of using Ansible Galaxy lies in its extensive library of roles that help address common configuration tasks across various operating systems.

  • For example, when tasked with installing Docker across multiple managed nodes with different OS flavors, rather than writing complex playbooks, users can search Ansible Galaxy for roles that fit their requirements.

  • Users are encouraged to evaluate the roles and their documentation to ensure they meet their needs, which can save time and increase efficiency.

Utilizing the Ansible Galaxy CLI 09:32

"To access Ansible Galaxy, you can use the Ansible Galaxy CLI utility, which might come pre-installed with Ansible."

  • The Ansible Galaxy CLI allows users to interact with the Galaxy ecosystem effectively, enabling operations like role initialization, search, import, and installation.

  • Users can initialize a role directory structure, remove existing roles, list available roles, and search for new ones directly from their command line interface.

  • The example given is about downloading a Docker role from Ansible Galaxy, showing how to set up an account and authenticate with GitHub for seamless access to the roles.

Community Contribution and Sharing Roles 12:08

"It resembles community work where individuals share their Ansible roles with others, allowing for collaborative quality enhancement."

  • Once users create or modify roles, they can publish them to Ansible Galaxy, contributing to a community where everyone benefits from shared resources.

  • As users explore various roles, they can see the popularity and download statistics of published roles, guiding them in choosing trustworthy and well-reviewed contributions from the community.

  • This collaborative aspect emphasizes the importance of sharing knowledge and resources within the DevOps community, enhancing overall productivity and best practices.

Installing Docker Roles with Ansible Galaxy 12:41

"To install a role, you simply go to your Ansible Galaxy and copy the installation command."

  • The video discusses how to install the Docker role using Ansible Galaxy, building upon previous playbooks and roles created in earlier lessons.

  • The user is instructed to execute the command to install the Docker role, which is confirmed by a message indicating that the role has already been installed.

  • Installed roles can be found in a hidden folder called .ansible_roles within the user's home directory.

Using Installed Roles in a Playbook 14:20

"You can reference the installed role in your playbook just as you did with the httpd role."

  • The instructor demonstrates how to utilize the installed Docker role in a new playbook by referencing it under the "roles" section of the YAML file.

  • After constructing the playbook, users are guided to execute it using an Ansible command, which will apply the tasks associated with the Docker role.

Benefits of Using Existing Ansible Roles 16:19

"Instead of writing a complicated Ansible playbook from scratch, you can use the existing Ansible role in Galaxy."

  • The video emphasizes the efficiency of using existing roles from Ansible Galaxy, highlighting that instead of writing extensive code, one can leverage pre-existing tasks which often cover a wide array of setups including different operating systems like Debian and Red Hat.

  • The instructor suggests verifying the installation by logging into the EC2 instance, where users should see that Docker is properly installed.

Publishing Ansible Roles to Galaxy 18:00

"Ansible roles should always be stored in GitHub and imported into Ansible Galaxy."

  • The process of publishing custom roles to Ansible Galaxy involves first creating a GitHub repository for the role, demonstrating the necessary steps to initialize and push the source code to GitHub.

  • Proper meta information should be added to the repository to help others understand the purpose and authorship of the role.

Importing the Role into Ansible Galaxy 22:00

"You need an API token from Ansible Galaxy to publish your role effectively."

  • After successfully pushing the role to GitHub, the next step is to import the role into Ansible Galaxy using the unique API token generated from Ansible Galaxy settings.

  • Once the role is published, it becomes available for other developers to use, thereby contributing to the community and facilitating collaboration.

Best Practices for Documentation 23:42

"It's essential to have well-documented roles so that users can understand their functionality."

  • The instructor encourages users to maintain accurate documentation within the repository, including the README file and meta information, highlighting that thorough documentation facilitates better usability and understanding within the organization.