From 903cfa63cbf51ba8af23862886dce79230f9c1cb Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Wed, 7 Nov 2018 11:09:32 -0500 Subject: [PATCH] make inventory warnings a bit smarter (#46284) less annoying for common cases add comment for 'tricky' conditional --- lib/ansible/cli/__init__.py | 2 +- lib/ansible/inventory/manager.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index 86d248098b..c09066e231 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -807,7 +807,7 @@ class CLI(with_metaclass(ABCMeta, object)): no_hosts = False if len(inventory.list_hosts()) == 0: # Empty inventory - if C.LOCALHOST_WARNING: + if C.LOCALHOST_WARNING and pattern not in C.LOCALHOST: display.warning("provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'") no_hosts = True diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index fc39e25db2..6e174a04f7 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -289,7 +289,9 @@ class InventoryManager(object): if C.INVENTORY_ANY_UNPARSED_IS_FAILED: raise AnsibleError(u'Completely failed to parse inventory source %s' % (source)) if not parsed: - display.warning("Unable to parse %s as an inventory source" % source) + if source != '/etc/ansible/hosts' or os.path.exists(source): + # only warn if NOT using the default and if using it, only if the file is present + display.warning("Unable to parse %s as an inventory source" % source) # clear up, jic self._inventory.current_source = None