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-hostsParameters & Attributes
| Name | Type | Description |
|---|---|---|
| PATTERN | operand | Host selection pattern |
| -i | option | Inventory source |
| --list-hosts | option | List 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