LOGBOOK

HELP

Quiz Entry - updated: 2026.10.30

How do you check whether a host or group is in the inventory, and when do you need -i?

Run ansible <host-or-group> --list-hosts: it prints the matching hosts without contacting them. Add -i <file> whenever the inventory is not the default one set in ansible.cfg.

$ ansible washington1.example.com --list-hosts
  hosts (1):
    washington1.example.com

$ ansible canada --list-hosts
  hosts (2):
    ontario01.example.com
    ontario02.example.com

$ ansible all -i hosts.yml --list-hosts
  hosts (3):
    ...

--list-hosts only resolves the pattern against the inventory; nothing runs on the machines. It is the quickest way to answer "does Ansible know this host?" or "which machines would this play hit?" before you change anything. A name that is not in the inventory gives a warning and hosts (0).

-i (inventory) is optional but very common. Without it, Ansible uses the inventory path from the inventory = line of the active ansible.cfg. If your file has a different name or location, you must pass it, for example -i hosts.yml.

Go deeper:

From Quiz: ITIA / Ansible Inventory, Configuration and Playbooks | Updated: Oct 30, 2026