# 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(fail_message.format(param=param))
            if module.params["auth_type"] != "password":
                module.fail_json(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 (TypeError)
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_ADuric/ansible_module_os_project.py", line 221, in <module>
main()
File "/tmp/ansible_ADuric/ansible_module_os_project.py", line 166, in main
module, min_version=min_version)
File "/tmp/ansible_ADuric/ansible_modlib.zip/ansible/module_utils/openstack.py", line 136, in openstack_cloud_from_module
TypeError: fail_json() takes exactly 1 argument (2 given)

fatal: [localhost]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_ADuric/ansible_module_os_project.py\", line 221, in <module>\n    main()\n  File \"/tmp/ansible_ADuric/ansible_module_os_project.py\", line 166, in main\n    module, min_version=min_version)\n  File \"/tmp/ansible_ADuric/ansible_modlib.zip/ansible/module_utils/openstack.py\", line 136, in openstack_cloud_from_module\nTypeError: fail_json() takes exactly 1 argument (2 given)\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}

# 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",
                "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))