1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

add toggle for host pattern mismatch behaviour (#51199)

* add toggle for host pattern mismatch behaviour

	fixes #40030

* fix
This commit is contained in:
Brian Coca 2019-01-25 16:00:28 -05:00 committed by ansibot
parent 315434f676
commit 9a1c291d01
2 changed files with 16 additions and 1 deletions

View file

@ -1391,6 +1391,15 @@ HOST_KEY_CHECKING:
ini: ini:
- {key: host_key_checking, section: defaults} - {key: host_key_checking, section: defaults}
type: boolean type: boolean
HOST_PATTERN_MISMATCH:
name: Control host pattern mismatch behaviour
default: 'warning'
description: This setting changes the behaviour of mismatched host patterns, it allows you to force a fatal error, a warning or just ignore it
env: [{name: ANSIBLE_HOST_PATTERN_MISMATCH}]
ini:
- {key: host_pattern_mismatch, section: inventory}
choices: ['warning', 'error', 'ignore']
version_added: "2.8"
INVALID_TASK_ATTRIBUTE_FAILED: INVALID_TASK_ATTRIBUTE_FAILED:
name: Controls whether invalid attributes for a task result in errors instead of warnings name: Controls whether invalid attributes for a task result in errors instead of warnings
default: True default: True

View file

@ -553,7 +553,13 @@ class InventoryManager(object):
# Display warning if specified host pattern did not match any groups or hosts # Display warning if specified host pattern did not match any groups or hosts
if not results and not matching_groups and pattern != 'all': if not results and not matching_groups and pattern != 'all':
display.warning("Could not match supplied host pattern, ignoring: %s" % pattern) msg = "Could not match supplied host pattern, ignoring: %s" % pattern
display.debug(msg)
if C.HOST_PATTERN_MISMATCH == 'warning':
display.warning(msg)
elif C.HOST_PATTERN_MISMATCH == 'error':
raise AnsibleOptionsError(msg)
# no need to write 'ignore' state
return results return results