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.
*This course is not approved or sponsored by Red Hat.*
Successfully complete this lab by achieving the following learning objectives:
- Fix the Ansible Inventory File
ansible all -m pingresults in a failure complaining about YAML parsing the inventory file. So we need to look at the Ansible inventory.
/etc/ansible/hostswe 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:
- 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
ansible -m setuppart grabs the facts, the
--tree /tmp/factsspecifies a directory for where to put the files containing these facts, and
localhostis the server we’re querying.
Now if we run
ls /tmp/facts, we’ll see
127.0.0.1sitting there. This file contains all of the facts about the server at
127.0.0.1. If we’d run that command with
localhost, then this directory would contain one file for each server in the inventory.