better handling of bad type in config (#48821)

* better handling of bad type in config

 fixes #22468, fixes #22476
This commit is contained in:
Brian Coca 2018-11-19 11:45:45 -05:00 committed by GitHub
parent a796299651
commit 87e44a7ed1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- better error message when bad type in config, deal with EVNAR= more gracefully https://github.com/ansible/ansible/issues/22470

View file

@ -436,7 +436,15 @@ class ConfigManager(object):
return value, origin
# ensure correct type, can raise exceptoins on mismatched types
value = ensure_type(value, defs[config].get('type'), origin=origin)
try:
value = ensure_type(value, defs[config].get('type'), origin=origin)
except ValueError as e:
if origin.startswith('env:') and value == '':
# this is empty env var for non string so we can set to default
origin = 'default'
value = ensure_type(defs[config].get('default'), defs[config].get('type'), origin=origin)
else:
raise AnsibleOptionsError('Invalid type for configuration option %s: %s' % (to_native(config), to_native(e)))
# deal with deprecation of the setting
if 'deprecated' in defs[config] and origin != 'default':

View file

@ -0,0 +1 @@
shippable/posix/group1

View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -eux
# ignore empty env var and use default
# shellcheck disable=SC1007
ANSIBLE_TIMEOUT= ansible -m ping localhost "$@"
# env var is wrong type, this should be a fatal error pointing at the setting
ANSIBLE_TIMEOUT='lola' ansible -m ping localhost "$@" 2>&1|grep 'AnsibleOptionsError: Invalid type for configuration option DEFAULT_TIMEOUT'