1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Rework the way ad-hoc filters inventory to match how cli/playbook does it

This commit is contained in:
James Cammarata 2016-02-25 12:36:44 -05:00
parent e2d2798a42
commit 771f1e31a9

View file

@ -124,13 +124,17 @@ class AdHocCLI(CLI):
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.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)
if len(hosts) == 0:
raise AnsibleError("Specified hosts options do not match any hosts")
if len(hosts) == 0 and no_hosts is False:
# Invalid limit
raise AnsibleError("Specified --limit does not match any hosts")
if self.options.listhosts:
display.display(' hosts (%d):' % len(hosts))