commands

ansible — Select inventory hosts

Select and list matching hosts without executing modules. Use the supplied localhost-only static inventory; avoid unreviewed dynamic inventory. Use a fresh private workspace; do not apply to a real system.

Formal Syntax & Structure

linux syntaxlinux
ansible PATTERN -i INVENTORY --list-hosts

Parameters & Attributes

NameTypeDescription
PATTERNoperandHost selection pattern
-ioptionInventory source
--list-hostsoptionList selected hosts without executing tasks

Return Value

exit status and output

The --list-hosts mode prints the hosts matching the pattern and inventory; it runs no modules. Inspect the selected host count and inventory warnings, even if the command exits successfully.

Working Example

Example Snippetlinux
ansible lab -i inventory.ini --list-hosts
Linux Reference