diff options
-rw-r--r-- | changelogs/fragments/any_unparsed_is_failed.yaml | 5 | ||||
-rw-r--r-- | lib/ansible/config/base.yml | 17 | ||||
-rw-r--r-- | lib/ansible/inventory/manager.py | 2 |
3 files changed, 23 insertions, 1 deletions
diff --git a/changelogs/fragments/any_unparsed_is_failed.yaml b/changelogs/fragments/any_unparsed_is_failed.yaml new file mode 100644 index 0000000000..465f4e2772 --- /dev/null +++ b/changelogs/fragments/any_unparsed_is_failed.yaml @@ -0,0 +1,5 @@ +--- +minor_changes: + - Added inventory.any_unparsed_is_failed configuration setting. In an + inventory with a static hosts file and (say) ec2.py, enabling this + setting will cause a failure instead of a warning if ec2.py fails. diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml index 9911f72f64..b555d6083b 100644 --- a/lib/ansible/config/base.yml +++ b/lib/ansible/config/base.yml @@ -1375,6 +1375,18 @@ HOST_KEY_CHECKING: ini: - {key: host_key_checking, section: defaults} type: boolean +INVENTORY_ANY_UNPARSED_IS_FAILED: + name: Controls whether any unparseable inventory source is a fatal error + default: False + description: > + If 'true', it is a fatal error when any given inventory source + cannot be successfully parsed by any available inventory plugin; + otherwise, this situation only attracts a warning. + type: boolean + env: [{name: ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED}] + ini: + - {key: any_unparsed_is_failed, section: inventory} + version_added: "2.7" INVENTORY_ENABLED: name: Active Inventory plugins default: ['host_list', 'script', 'yaml', 'ini', 'auto'] @@ -1412,7 +1424,10 @@ INVENTORY_IGNORE_PATTERNS: INVENTORY_UNPARSED_IS_FAILED: name: Unparsed Inventory failure default: False - description: If 'true' unparsed inventory sources become fatal errors, they are warnings otherwise. + description: > + If 'true' it is a fatal error if every single potential inventory + source fails to parse, otherwise this situation will only attract a + warning. env: [{name: ANSIBLE_INVENTORY_UNPARSED_FAILED}] ini: - {key: unparsed_is_failed, section: inventory} diff --git a/lib/ansible/inventory/manager.py b/lib/ansible/inventory/manager.py index 0772cff636..29f95de626 100644 --- a/lib/ansible/inventory/manager.py +++ b/lib/ansible/inventory/manager.py @@ -285,6 +285,8 @@ class InventoryManager(object): display.warning(u'\n* Failed to parse %s with %s plugin: %s' % (to_text(fail['src']), fail['plugin'], to_text(fail['exc']))) if hasattr(fail['exc'], 'tb'): display.vvv(to_text(fail['exc'].tb)) + if C.INVENTORY_ANY_UNPARSED_IS_FAILED: + raise AnsibleError(u'Completely failed to parse inventory source %s' % (to_text(source))) if not parsed: display.warning("Unable to parse %s as an inventory source" % to_text(source)) |