Understand Core Components of Ansible - Inventories and Facts

Get Started
45 minutes
  • 2 Learning Objectives

About this Hands-on Lab

The key to understanding Ansible lies with beginning to actually use Ansible. Grasping the basic concepts of inventories and facts is crucial to using Ansible, both in simple and more advanced implementations. This lab will make sure you have this basic understanding of where Ansible inventory files are, and how to set them up.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Fix the Ansible Inventory File

Running ansible all -m ping results in a failure complaining about YAML parsing the inventory file. So we need to look at the Ansible inventory.

Looking at /etc/ansible/hosts we can see that there’s a comment line that isn’t commented out,
and that the only server listed is an example IP. Fixing the comment and changing the IP to
127.0.0.1, and then saving the file, will allow the command to work. It should end up looking similar to this:

127.0.0.1
Generate a List of Facts About the Ansible Host

The easiest way to accomplish this task is with a one-liner:

ansible -m setup --tree /tmp/facts localhost

The ansible -m setup part grabs the facts, the --tree /tmp/facts specifies a directory for where to put the files containing these facts, and localhost is the server we’re querying.

Now if we run ls /tmp/facts, we’ll see 127.0.0.1 sitting there. This file contains all of the facts about the server at 127.0.0.1. If we’d run that command with all instead of localhost, then this directory would contain one file for each server in the inventory.

Additional Resources

Notice: Ansible is installed as the root user, so please work on all tasks after elevating to the root user.

Our company hired a consultant to set up an Ansible proof of concept. Unfortunately the consultant didn't complete the setup and we've been tasked with doing it. While management deals with the consultant, we've discovered that Ansible has been installed but configured incorrectly. We need to fix the inventory so that ansible all -m ping works correctly, and then generate a list of facts about this system. We'll store these facts in /tmp/facts/.

Logging In

Use the credentials provided on the hands-on lab page to get into the public instance to begin with. Since we need root privileges, let's just run sudo -i right off and become root.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?