From e8e1d9f6fbc9f57af102aa765a354ace87ba7b41 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 23 Sep 2015 08:28:38 -0400 Subject: [PATCH] Apply --limit to inventory in adhoc commands Fixes #12473 --- lib/ansible/cli/adhoc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 9b6957cfbb..235aa56fdb 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -112,8 +112,15 @@ class AdHocCLI(CLI): variable_manager.set_inventory(inventory) hosts = inventory.list_hosts(pattern) + no_hosts = False if len(hosts) == 0: self.display.warning("provided hosts list is empty, only localhost is available") + no_hosts = True + + inventory.subset(self.options.subset) + if len(inventory.list_hosts()) == 0 and not no_hosts: + # Invalid limit + raise AnsibleError("Specified --limit does not match any hosts") if self.options.listhosts: self.display.display(' hosts (%d):' % len(hosts))