# Buggy code
def openstack_cloud_from_module(module, min_version="0.12.0"):
    from distutils.version import StrictVersion

    try:
        # Due to the name shadowing we should import other way
        import importlib

        sdk = importlib.import_module("openstack")
    except ImportError:
        module.fail_json(msg="openstacksdk is required for this module")

    if min_version:
        if StrictVersion(sdk.version.__version__) < StrictVersion(min_version):
            module.fail_json(
                msg="To utilize this module, the installed version of"
                "the openstacksdk library MUST be >={min_version}".format(
                    min_version=min_version
                )
            )

    cloud_config = module.params.pop("cloud", None)
    try:
        if isinstance(cloud_config, dict):
            fail_message = (
                "A cloud config dict was provided to the cloud parameter"
                " but also a value was provided for {param}. If a cloud"
                " config dict is provided, {param} should be"
                " excluded."
            )
            for param in (
                "auth",
                "region_name",
                "verify",
                "cacert",
                "key",
                "api_timeout",
                "interface",
            ):
                if module.params[param] is not None:
                    module.fail_json(msg=fail_message.format(param=param))
            if module.params["auth_type"] != "password":
                module.fail_json(msg=fail_message.format(param="auth_type"))
            return sdk, sdk.connect(**cloud_config)
        else:
            return sdk, sdk.connect(
                cloud=cloud_config,
                auth_type=module.params["auth_type"],
                auth=module.params["auth"],
                region_name=module.params["region_name"],
                verify=module.params["verify"],
                cacert=module.params["cacert"],
                key=module.params["key"],
                api_timeout=module.params["api_timeout"],
                interface=module.params["interface"],
            )
    except sdk.exceptions.SDKException as e:
        # Probably a cloud configuration/login error
        module.fail_json(msg=str(e))


# Traceback (nTypeError)
"module_stderr": "OpenSSH_7.2p2 Ubuntu-4ubuntu2.4, OpenSSL 1.0.2g  1 Mar 2016\r\ndebug1: Reading configuration data /home/ckoester/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 16121\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 1\r\nShared connection to inception-ngena3.ngena.ciscolabs.com closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n  File \"/tmp/ansible_oGfmKg/ansible_module_os_project.py\", line 209, in <module>\r\n    main()\r\n  File \"/tmp/ansible_oGfmKg/ansible_module_os_project.py\", line 154, in main\r\n    sdk, cloud = openstack_cloud_from_module(module)\r\n  File \"/tmp/ansible_oGfmKg/ansible_modlib.zip/ansible/module_utils/openstack.py\", line 139, in openstack_cloud_from_module\r\nTypeError: fail_json() takes exactly 1 argument (2 given)\r\n",

# Fixed code
def openstack_cloud_from_module(module, min_version="0.12.0"):
    from distutils.version import StrictVersion

    try:
        # Due to the name shadowing we should import other way
        import importlib

        sdk = importlib.import_module("openstack")
    except ImportError:
        module.fail_json(msg="openstacksdk is required for this module")

    if min_version:
        if StrictVersion(sdk.version.__version__) < StrictVersion(min_version):
            module.fail_json(
                msg="To utilize this module, the installed version of"
                "the openstacksdk library MUST be >={min_version}".format(
                    min_version=min_version
                )
            )

    cloud_config = module.params.pop("cloud", None)
    try:
        if isinstance(cloud_config, dict):
            fail_message = (
                "A cloud config dict was provided to the cloud parameter"
                " but also a value was provided for {param}. If a cloud"
                " config dict is provided, {param} should be"
                " excluded."
            )
            for param in (
                "auth",
                "region_name",
                "verify",
                "cacert",
                "key",
                "api_timeout",
                "auth_type",
            ):
                if module.params[param] is not None:
                    module.fail_json(msg=fail_message.format(param=param))
            # For 'interface' parameter, fail if we receive a non-default value
            if module.params["interface"] != "public":
                module.fail_json(msg=fail_message.format(param="interface"))
            return sdk, sdk.connect(**cloud_config)
        else:
            return sdk, sdk.connect(
                cloud=cloud_config,
                auth_type=module.params["auth_type"],
                auth=module.params["auth"],
                region_name=module.params["region_name"],
                verify=module.params["verify"],
                cacert=module.params["cacert"],
                key=module.params["key"],
                api_timeout=module.params["api_timeout"],
                interface=module.params["interface"],
            )
    except sdk.exceptions.SDKException as e:
        # Probably a cloud configuration/login error
        module.fail_json(msg=str(e))