make inventory warnings a bit smarter (#46284)

less annoying for common cases
 add comment for 'tricky' conditional
pull/48305/head
Brian Coca 6 years ago committed by GitHub
parent 4961f003e5
commit 903cfa63cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -807,7 +807,7 @@ class CLI(with_metaclass(ABCMeta, object)):
no_hosts = False no_hosts = False
if len(inventory.list_hosts()) == 0: if len(inventory.list_hosts()) == 0:
# Empty inventory # 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'") display.warning("provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'")
no_hosts = True no_hosts = True

@ -289,6 +289,8 @@ class InventoryManager(object):
if C.INVENTORY_ANY_UNPARSED_IS_FAILED: if C.INVENTORY_ANY_UNPARSED_IS_FAILED:
raise AnsibleError(u'Completely failed to parse inventory source %s' % (source)) raise AnsibleError(u'Completely failed to parse inventory source %s' % (source))
if not parsed: if not parsed:
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) display.warning("Unable to parse %s as an inventory source" % source)
# clear up, jic # clear up, jic

Loading…
Cancel
Save