summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhijit Menon-Sen <ams@2ndQuadrant.com>2018-06-01 21:06:42 +0530
committerAbhijit Menon-Sen <ams@2ndQuadrant.com>2018-06-01 21:06:42 +0530
commit441285d67b74a3777cf90df5e2d34d78211a7854 (patch)
treeda128f996b8f592468b5f1aa94821360257c70b5
parent1cec3c8daf044b9a65e31b0da3eda2661c2fbff1 (diff)
downloadansible-inventory_errors_fatal.tar.gz
Introduce inventory.any_errors_fatal configuration settinginventory_errors_fatal
First, we clarify that "unparsed_is_failed=true" causes a fatal error only if ALL available inventory sources completely fail to parse. In other words, if there is a static inventory source (yaml/ini-format) defined, then no combination of parsing failures and the setting can result in a fatal error. This is not what everyone needs. When you have a complex inventory with multiple sources, it is useful to treat any error as fatal, rather than proceeding with playbook execution with an incomplete inventory. This commit introduces an "any_errors_fatal" setting that does exactly this: if we completely fail to parse any given inventory source, it is treated as a fatal error.
-rw-r--r--lib/ansible/config/base.yml17
-rw-r--r--lib/ansible/inventory/manager.py2
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/ansible/config/base.yml b/lib/ansible/config/base.yml
index 020ffeb0c7..1becb5330c 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_ERRORS_FATAL:
+ 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_ERRORS_FATAL}]
+ ini:
+ - {key: any_errors_fatal, 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..a39bc620f1 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_ERRORS_FATAL:
+ 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))