# Buggy code
def update_config_data(self, defs=None, configfile=None):
    """really: update constants"""

    if defs is None:
        defs = self._base_defs

    if configfile is None:
        configfile = self._config_file

    if not isinstance(defs, dict):
        raise AnsibleOptionsError(
            "Invalid configuration definition type: %s for %s" % (type(defs), defs)
        )

    # update the constant for config file
    self.data.update_setting(Setting("CONFIG_FILE", configfile, "", "string"))

    origin = None
    # env and config defs can have several entries, ordered in list from lowest to highest precedence
    for config in defs:
        if not isinstance(defs[config], dict):
            raise AnsibleOptionsError(
                "Invalid configuration definition '%s': type is %s"
                % (to_native(config), type(defs[config]))
            )

        # get value and origin
        value, origin = self.get_config_value_and_origin(config, configfile)

        # set the constant
        self.data.update_setting(
            Setting(config, value, origin, defs[config].get("type", "string"))
        )


# Traceback (OptionValueError)
[fedora-25:ansible (devel % u=)]$ ANSIBLE_TIMEOUT= ansible -vvv localhost -m ping
ERROR! Unexpected Exception: option --timeout: invalid integer value: u''
the full traceback was:

Traceback (most recent call last):
File "/home/adrian/src/ansible/bin/ansible", line 102, in <module>
cli.parse()
File "/home/adrian/src/ansible/lib/ansible/cli/adhoc.py", line 75, in parse
super(AdHocCLI, self).parse()
File "/home/adrian/src/ansible/lib/ansible/cli/__init__.py", line 438, in parse
self.options, self.args = self.parser.parse_args(self.args[1:])
File "/usr/lib64/python2.7/optparse.py", line 1384, in parse_args
values = self.get_default_values()
File "/usr/lib64/python2.7/optparse.py", line 1329, in get_default_values
defaults[option.dest] = option.check_value(opt_str, default)
File "/usr/lib64/python2.7/optparse.py", line 770, in check_value
return checker(self, opt, value)
File "/usr/lib64/python2.7/optparse.py", line 430, in check_builtin
_("option %s: invalid %s value: %r") % (opt, what, value))
OptionValueError: option --timeout: invalid integer value: u''

# Fixed code
def update_config_data(self, defs=None, configfile=None):
    """really: update constants"""

    if defs is None:
        defs = self._base_defs

    if configfile is None:
        configfile = self._config_file

    if not isinstance(defs, dict):
        raise AnsibleOptionsError(
            "Invalid configuration definition type: %s for %s" % (type(defs), defs)
        )

    # update the constant for config file
    self.data.update_setting(Setting("CONFIG_FILE", configfile, "", "string"))

    origin = None
    # env and config defs can have several entries, ordered in list from lowest to highest precedence
    for config in defs:
        if not isinstance(defs[config], dict):
            raise AnsibleOptionsError(
                "Invalid configuration definition '%s': type is %s"
                % (to_native(config), type(defs[config]))
            )

        # get value and origin
        try:
            value, origin = self.get_config_value_and_origin(config, configfile)
        except Exception as e:
            # when building constants.py we ignore invalid configs
            # CLI takes care of warnings once 'display' is loaded
            self.UNABLE[config] = to_text(e)
            continue

        # set the constant
        self.data.update_setting(
            Setting(config, value, origin, defs[config].get("type", "string"))
        )