mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
fixed confusing reporting when no hosts are matched
it was hitting 'empty inventory' warning.
This commit is contained in:
@@ -130,7 +130,7 @@ class AdHocCLI(CLI):
|
|||||||
variable_manager.set_inventory(inventory)
|
variable_manager.set_inventory(inventory)
|
||||||
|
|
||||||
no_hosts = False
|
no_hosts = False
|
||||||
if len(inventory.list_hosts(pattern)) == 0:
|
if len(inventory.list_hosts()) == 0:
|
||||||
# Empty inventory
|
# Empty inventory
|
||||||
display.warning("provided hosts list is empty, only localhost is available")
|
display.warning("provided hosts list is empty, only localhost is available")
|
||||||
no_hosts = True
|
no_hosts = True
|
||||||
@@ -139,7 +139,7 @@ class AdHocCLI(CLI):
|
|||||||
hosts = inventory.list_hosts(pattern)
|
hosts = inventory.list_hosts(pattern)
|
||||||
if len(hosts) == 0 and no_hosts is False:
|
if len(hosts) == 0 and no_hosts is False:
|
||||||
# Invalid limit
|
# Invalid limit
|
||||||
raise AnsibleError("Specified --limit does not match any hosts")
|
raise AnsibleError("Specified hosts and/or --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))
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import sys
|
|||||||
|
|
||||||
from ansible import constants as C
|
from ansible import constants as C
|
||||||
from ansible.cli import CLI
|
from ansible.cli import CLI
|
||||||
from ansible.errors import AnsibleError, AnsibleOptionsError
|
from ansible.errors import AnsibleError
|
||||||
|
|
||||||
from ansible.executor.task_queue_manager import TaskQueueManager
|
from ansible.executor.task_queue_manager import TaskQueueManager
|
||||||
from ansible.inventory import Inventory
|
from ansible.inventory import Inventory
|
||||||
@@ -419,13 +419,19 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||||||
self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager, host_list=self.options.inventory)
|
self.inventory = Inventory(loader=self.loader, variable_manager=self.variable_manager, host_list=self.options.inventory)
|
||||||
self.variable_manager.set_inventory(self.inventory)
|
self.variable_manager.set_inventory(self.inventory)
|
||||||
|
|
||||||
if len(self.inventory.list_hosts(self.pattern)) == 0:
|
no_hosts = False
|
||||||
|
if len(self.inventory.list_hosts()) == 0:
|
||||||
# Empty inventory
|
# Empty inventory
|
||||||
|
no_hosts = True
|
||||||
display.warning("provided hosts list is empty, only localhost is available")
|
display.warning("provided hosts list is empty, only localhost is available")
|
||||||
|
|
||||||
self.inventory.subset(self.options.subset)
|
self.inventory.subset(self.options.subset)
|
||||||
|
hosts = self.inventory.list_hosts(self.pattern)
|
||||||
|
if len(hosts) == 0 and not no_hosts:
|
||||||
|
raise AnsibleError("Specified hosts and/or --limit does not match any hosts")
|
||||||
|
|
||||||
self.groups = self.inventory.list_groups()
|
self.groups = self.inventory.list_groups()
|
||||||
self.hosts = [x.name for x in self.inventory.list_hosts(self.pattern)]
|
self.hosts = [x.name for x in hosts]
|
||||||
|
|
||||||
# This hack is to work around readline issues on a mac:
|
# This hack is to work around readline issues on a mac:
|
||||||
# http://stackoverflow.com/a/7116997/541202
|
# http://stackoverflow.com/a/7116997/541202
|
||||||
|
|||||||
Reference in New Issue
Block a user