Working with Ansible Inventories

1 hour
  • 6 Learning Objectives

About this Hands-on Lab

Ansible relies on an inventory for base functionality. While inventories can be very simple, they have been designed to be robust. This exercise walks through how to use some of the more advanced features available within an Ansible inventory. Upon completion of this exercise, students will have practical experience with Ansible inventory configuration.

*This course is not approved or sponsored by Red Hat.*

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the inventory File in /home/ansible/

Create the inventory file in /home/ansible/.

Configure the media Host Group to Contain media1 and media2

Use an editor, such as Vim, to configure the media host group to contain media1 and media2.

Define Variables for media with Their Accompanying Values

Define the following variables for media with their accompanying values:

  • media_content should be set to /tmp/var/media/content/.
  • media_index should be set to /tmp//opt/media/mediaIndex.
Configure the webservers Host Group to Contain the Hosts web1 and web2

Configure the webservers host group to contain the hosts web1 and web2.

Define Variables for webservers with Their Accompanying Values

Define the following variables for webservers with their accompanying values:

  • httpd_webroot should be set to /var/www/.
  • httpd_config should be set to /etc/httpd/.
Define the script_files Variable for web1 and Set Its Value to /usr/local/scripts
  1. Define the variable script_files specifically for web1. The value of script_files should be set to /tmp/usr/local/scripts.
  2. To test your inventory, run /home/ansible/scripts/backup.sh.

    If you have correctly configured the inventory, it should not error.

    Note: Do not edit anything in /home/ansible/scripts/.

Additional Resources

Your company decided that their backup software license was frivolous and unnecessary. Because of this, the license was not renewed. As a stopgap measure, your supervisor has created a simple script and an Ansible playbook to create an archive of select files, depending on pre-defined Ansible host groups. You will create the inventory file to complete the backup strategy.


Important notes:

  • For your convenience, Ansible has been installed on the control node.
  • The user ansible has already been created on all servers with appropriate shared keys for access to managed servers from the control node.
  • The ansible user has the same password as cloud_user.
  • /etc/hosts entries have been made on control1 for the managed servers.

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?