mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
Rework the way ad-hoc filters inventory to match how cli/playbook does it
This commit is contained in:
parent
e2d2798a42
commit
771f1e31a9
1 changed files with 9 additions and 5 deletions
|
@ -124,13 +124,17 @@ class AdHocCLI(CLI):
|
||||||
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
|
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
|
||||||
variable_manager.set_inventory(inventory)
|
variable_manager.set_inventory(inventory)
|
||||||
|
|
||||||
|
no_hosts = False
|
||||||
|
if len(inventory.list_hosts(pattern)) == 0:
|
||||||
|
# Empty inventory
|
||||||
|
display.warning("provided hosts list is empty, only localhost is available")
|
||||||
|
no_hosts = True
|
||||||
|
|
||||||
if self.options.subset:
|
|
||||||
inventory.subset(self.options.subset)
|
inventory.subset(self.options.subset)
|
||||||
|
|
||||||
hosts = inventory.list_hosts(pattern)
|
hosts = inventory.list_hosts(pattern)
|
||||||
if len(hosts) == 0:
|
if len(hosts) == 0 and no_hosts is False:
|
||||||
raise AnsibleError("Specified hosts options do not match any hosts")
|
# Invalid limit
|
||||||
|
raise AnsibleError("Specified --limit does not match any hosts")
|
||||||
|
|
||||||
if self.options.listhosts:
|
if self.options.listhosts:
|
||||||
display.display(' hosts (%d):' % len(hosts))
|
display.display(' hosts (%d):' % len(hosts))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue