Navigating Ansible's Documentation: Plugins, Modules, and More! (Part 6)

Broadening Your Ansible Horizons: From Inventory to Azure AD

Image by storyset on Freepik

Image by storyset on Freepik

Hello Muser!

In our last deep dive, we executed your first Ansible playbook, focusing on the Pi-hole playbook. If you've been diligently following along, you might be thinking, "All right, I've got the basics down. I can follow along and write a playbook from someone else’s imagination. But what's the next step in writing MY OWN Ansible playbooks?".

The Ansible Hammer in Your Toolkit

I'm sure you know the saying, "If all you have is a hammer, everything looks like a nail". As you get more comfortable with Ansible, you might find yourself trying to use it for everything. And that's not a bad thing! Experimenting with Ansible across different scenarios will teach you where it fits best and where you might need a different tool.

----------

Ansible Plugins

Ansible's popularity and power come from its range of plugins. While there are many different types of plugins (which you can review here) I want to highlight 3 in particular:

1. Inventory Plugins: These plugins allow Ansible to fetch inventory data from various sources. For instance, you can pull inventory from cloud providers like AWS or Azure, or even from sources like LDAP directories.

2. Lookup Plugins: These plugins help Ansible fetch data from external sources. For example, you can retrieve secrets from a vault, fetch data from a database, or even read values from a CSV file for use in your playbooks.

1. Module Plugins: These are the core of Ansible, enabling specific tasks. From managing files to orchestrating cloud tasks, modules are essential.

----------

A Closer Look at Modules

To truly grasp Ansible's capabilities, you'll need to delve into its extensive collection of modules. This page is a full index of modules and will show you just how much is possible with Ansible.

What you want to do is browse through the list just to get an idea of the range of actions you can take. There are modules for technologies that I've never touched and aren't relevant to me, but you never know what will jump out until you look.

To kickstart your exploration, here are some modules that might be of interest:

- Windows Modules: For those managing Windows environments, these modules cover everything from file management to PowerShell commands.

- Cisco IOS Modules: For the network enthusiasts, these modules allow you to automate and manage tasks on Cisco devices.

- Azure Modules: Those working with Microsoft Azure will find these modules invaluable for tasks across all of Azure’s services.

----------

So How Do I Use A Module?

If you haven't gathered yet, there's a lot of documentation to read so you'll want to get comfortable with the idea sooner rather than later. Let's take an example: the azure.azcollection.azure_rm_aduser module.

There's a ton of information. Let's start at the top:

Provided in the Note section is information on how to install/download this particular module for use. Underneath is the table of contents for this documentation page.

Scrolling down a bit farther, the Parameters section details each of the knobs, toggles, and switches you can tweak. The details here give more information on how to use the various settings you can change. If you’re not sure exactly what kind of information to provide for each parameter, here is where you’ll find out.

The Examples section gives you syntax that you can combine with the Parameters to understand how to put it all together.

Lastly, the Return Values section tells you about information that is returned for use in registers (a type of ansible variable). As an example, you can use the returned mail value from the screenshot above, store it in a register, and use it as a parameter in your next task!

----------

Take Baby Steps

This is a lot of information, and you won’t memorize it all at once. I wanted to write this because too often, I see tutorials that don’t touch on how to use the documentation to get beyond the severely limited scope of the topic at hand. I personally feel that learning to read and use documentation is not talked about enough and wanted to provide this as a reference you can use to start picking apart what you need from the official docs.

As you attempt to write your own playbooks, the official documentation becomes a handbook for everything you need, but you don’t need to read it front-to-back.

Lay out the structure of what you want to do beforehand and consult the docs to figure out how to do it.

Need to do loops? Learn it when it comes up.

Need to do conditionals? Try it out by applying it when you need it.

Need to see some context? The official ansible-examples repo on Github is a great resource to see how someone else would do it.

Little by little, you’ll encounter situations that require more sophisticated playbooks and logic. In the same way that you’re adding Ansible as a tool to your System Administration/Operations skillset, you’ll add Ansible syntax and features to your playbooks, making them more robust and powerful.

If you’ve read this far, thanks for following all the way through! Ask me a question and try to stump me in the comments! Tell me ways I can make improvements!

----------

Enjoyed this post? Don't miss the next one. Subscribe now and receive a 5 page, printable cheat sheet PDF with 200+ vital commands for Linux, Ansible, Docker, and Terraform!

Keep learning and keep growing,

Darrell

Reply

or to participate.