Difficulty: beginner
Estimated Time: 15 minutes

Ansible is a configuration management and orchestration tool. It works as an IT automation engine. Ansible can be run directly from the command line without setting up any configuration files. You only need to install Ansible on the control server or node. It communicates and performs the required tasks using SSH. No other installation is required.

In this module we will be refreshing your knowledge of Ansible. Exercises are meant to help you practice/review your skills.

Summarizing what we reviewed:

  • How to setup an inventory file
  • How to create and run a playbook
  • How to create a role
  • How to reference a role in a playbook
  • How to use variables in roles

Ansible Review

Step 1 of 9

Creating an Inventory

In Ansible, the inventory represents the machines that Ansible will manage. Without an inventory, you would have a set of playbooks that define your desired system state, but wouldn’t know which machines you needed to run them against.

By default, Ansible will read /etc/ansible/hosts as its default inventory file. But you should maintain a different inventory file for each project that you have and pass it to both the ansible and ansible-playbook commands using the –i option.

Here is an example of passing a custom inventory file to ansible before running the ping module:

ansible all –i /path/to/inventory –m ping

In this tutorial you have access to one host named host01. To let Ansible know about it, put its hostname in an inventory file.

1. We'll call our inventory file myhosts, and you'll add one group called group1:

echo "[group1]" > myhosts

2. Then, add the host to the group, while also passing the username to use for SSH access, as an inventory parameter.

echo "host01 ansible_ssh_user=cent" >> myhosts

3. You can use your terminal to verify that myhosts has been created: cat myhosts

4. You can also run the following command to verify that your inventory is working properly:

ansible all -i myhosts -m ping

The response should look be:

host01 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

So, now that we have confirmed Ansible is properly configured, let's look at Ansible Playbooks.

playbook.yml

Creating Katacoda Scenarios

Thanks for creating Katacoda scenarios. This tab is designed to help you as an author have quick access the information you need when creating scenarios.

This tab will not be visible to users.

Here are some useful links to get you started.

Running Katacoda Workshops

If you are planning to use Katacoda for workshops, please contact [email protected] to arrange capacity.

Debugging Scenarios

Below is the response from any background scripts run or files uploaded. This stream can aid debugging scenarios.

If you still need assistance, please contact [email protected]