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 1 of 5 · on a machine · 6 min

Ansible did not connect to the machine

What you will learn

  • Describe machines in an inventory — name, address ansible_host, user ansible_user, group — and tell from an UNREACHABLE answer what is wrong with the line.
  • Run ad-hoc commands ansible <machines> -m <module> -a '…' and tell a CHANGED answer from SUCCESS.
  • Run a module as root with -b and describe a machine in the inventory that Ansible reaches without SSH.

The app1 application server is configured with Ansible: the program logs in to machines over SSH and does the work it is given there. A colleague left a list of machines in ~/ansible-lab. Before changing anything, check the connection: ansible all -m ping goes round every machine on the list.

Exercise · look

Check the connection to the machine on the list

In ~/ansible-lab look at your colleague's list of machines, check the connection to them with ansible all -m ping and find the lab.test lines in /etc/hosts.

First, predict

There is one machine on the list — app1. What will Ansible answer about it?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Check yourself 1 question

Ansible answered “UNREACHABLE!” for app1. Why did it not connect?

  • UNREACHABLE! is a connection error; the module never ran. Ansible brings the module to the machine itself on every run.

  • SSH did not even find the address — “Could not resolve hostname”: it never reached the service. systemctl is-active ssh answers active.

  • Ansible started and printed an answer — student has the rights. The message in the answer is about the machine's name: Could not resolve hostname.

SSH found no address for app1.lab.test: there is no such name in /etc/hosts.

Ubuntu 24.04
Loading…