# Buggy code
def create_one_client(self):
    """
    Creates an XMLPRC client to OpenNebula.

    Returns: the new xmlrpc client.

    """

    # context required for not validating SSL, old python versions won't validate anyway.
    if hasattr(ssl, "_create_unverified_context"):
        no_ssl_validation_context = ssl._create_unverified_context()
    else:
        no_ssl_validation_context = None

    # Check if the module can run
    if not HAS_PYONE:
        self.fail("pyone is required for this module")

    if "api_url" in self.module.params:
        url = self.module.params.get("api_url", environ.get("ONE_URL", False))
    else:
        self.fail("Either api_url or the environment variable ONE_URL must be provided")

    if "api_username" in self.module.params:
        username = self.module.params.get(
            "api_username", environ.get("ONE_USERNAME", False)
        )
    else:
        self.fail(
            "Either api_username or the environment vairable ONE_USERNAME must be provided"
        )

    if "api_password" in self.module.params:
        password = self.module.params.get(
            "api_password", environ.get("ONE_PASSWORD", False)
        )
    else:
        self.fail(
            "Either api_password or the environment vairable ONE_PASSWORD must be provided"
        )

    session = "%s:%s" % (username, password)

    if (
        not self.module.params.get("validate_certs")
        and "PYTHONHTTPSVERIFY" not in environ
    ):
        return OneServer(url, session=session, context=no_ssl_validation_context)
    else:
        return OneServer(url, session)


# Traceback (TypeError)
Error message is:
TASK [one_host] ****************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: expected string or buffer

fatal: [localhost]: FAILED! => changed=false

module_stderr: |-

Traceback (most recent call last):

File "/tmp/ansible_00gOZ_/ansible_module_one_host.py", line 280, in <module>

main()

File "/tmp/ansible_00gOZ_/ansible_module_one_host.py", line 276, in main

HostModule().run_module()

File "/tmp/ansible_00gOZ_/ansible_module_one_host.py", line 138, in __init__

OpenNebulaModule.__init__(self, argument_spec, mutually_exclusive=mutually_exclusive)

File "/tmp/ansible_00gOZ_/ansible_modlib.zip/ansible/module_utils/opennebula.py", line 49, in __init__

File "/tmp/ansible_00gOZ_/ansible_modlib.zip/ansible/module_utils/opennebula.py", line 89, in create_one_client

File "/usr/lib/python2.7/site-packages/pyone/__init__.py", line 167, in __init__

xmlrpc.client.ServerProxy.__init__(self, uri, **options)

File "/usr/lib64/python2.7/xmlrpclib.py", line 1560, in __init__

type, uri = urllib.splittype(uri)

File "/usr/lib64/python2.7/urllib.py", line 1071, in splittype

match = _typeprog.match(url)

TypeError: expected string or buffer
module_stdout: ‘’

msg: MODULE FAILURE

rc: 1

# Fixed code
def create_one_client(self):
    """
    Creates an XMLPRC client to OpenNebula.

    Returns: the new xmlrpc client.

    """

    # context required for not validating SSL, old python versions won't validate anyway.
    if hasattr(ssl, "_create_unverified_context"):
        no_ssl_validation_context = ssl._create_unverified_context()
    else:
        no_ssl_validation_context = None

    # Check if the module can run
    if not HAS_PYONE:
        self.fail("pyone is required for this module")

    if self.module.params.get("api_url"):
        url = self.module.params.get("api_url")
    else:
        self.fail("Either api_url or the environment variable ONE_URL must be provided")

    if self.module.params.get("api_username"):
        username = self.module.params.get("api_username")
    else:
        self.fail(
            "Either api_username or the environment vairable ONE_USERNAME must be provided"
        )

    if self.module.params.get("api_password"):
        password = self.module.params.get("api_password")
    else:
        self.fail(
            "Either api_password or the environment vairable ONE_PASSWORD must be provided"
        )

    session = "%s:%s" % (username, password)

    if (
        not self.module.params.get("validate_certs")
        and "PYTHONHTTPSVERIFY" not in environ
    ):
        return OneServer(url, session=session, context=no_ssl_validation_context)
    else:
        return OneServer(url, session)