Linux Labs

Automation: Git and Ansible / Stage 4 of 6

Inventory and ad-hoc commands

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 5 · on a machine · 8 min

The inventory: name, address, user

Ansible takes machines from the inventory and logs in to each over SSH. One mistake in a machine's line, and the work itself never starts.

The inventory is a file listing machines. The ansible.cfg file in the current directory points to it with inventory = inventory.ini, so ansible all in ~/ansible-lab finds the list on its own. Your colleague's machine line:

ini
[web]
app1 ansible_host=app1.lab.test ansible_user=deploy
Part Meaning
[web] a group: several machines under one name; all is every machine in the inventory
app1 the machine's name in Ansible: you write it in commands and see it in answers
ansible_host the address SSH goes to; without it SSH goes to the machine's name
ansible_user who to log in as; without it, whoever started Ansible

Ansible connects the same way as ssh deploy@app1.lab.test (SSH), and on the machine it runs a module — a small python program that does the work and answers. So UNREACHABLE! means one thing: SSH did not connect and the module never ran. Look for the cause in the name, the address, the user and the key (the three SSH messages are in the Wiki). What Ansible made of the inventory is shown by ansible-inventory --graph (groups) and ansible-inventory --host app1 (the machine's variables).

In this lesson app.lab.test is the address of this very machine, 127.0.0.1: Ansible logs in to it over SSH as if it were a neighbouring server.

Exercise · do it

Fix the app1 line in the inventory

Fix ~/ansible-lab/inventory.ini so that ansible all -m ping gets pong from app1 over SSH. Keep app1 as the machine's name in the inventory; Ansible has to log in under an account that has an SSH key.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Give an address SSH can find the machine by not done yet
  • Get pong from app1 over SSH not done yet

Step goals

0 of 2
  • Give an address SSH can find the machine by — not done yet
  • Get pong from app1 over SSH — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Give an address SSH can find the machine by — not done yet
  • Get pong from app1 over SSH — not done yet
Loading…