From 771f1e31a9588129eb92b269ac94fb714780d400 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Thu, 25 Feb 2016 12:36:44 -0500 Subject: [PATCH] Rework the way ad-hoc filters inventory to match how cli/playbook does it --- lib/ansible/cli/adhoc.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 7a3e208f368..dcb65ad135f 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -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))