# Buggy code
def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None):
    self.log("Getting management service client {0}".format(client_type.__name__))
    self.check_client_version(client_type)
    if api_version:
        client = client_type(
            self.azure_credentials,
            self.subscription_id,
            api_version=api_version,
            base_url=base_url,
        )
    else:
        client = client_type(
            self.azure_credentials, self.subscription_id, base_url=base_url
        )

    # Add user agent for Ansible
    client.config.add_user_agent(ANSIBLE_USER_AGENT)
    # Add user agent when running from Cloud Shell
    if CLOUDSHELL_USER_AGENT_KEY in os.environ:
        client.config.add_user_agent(os.environ[CLOUDSHELL_USER_AGENT_KEY])
    # Add user agent when running from VSCode extension
    if VSCODEEXT_USER_AGENT_KEY in os.environ:
        client.config.add_user_agent(os.environ[VSCODEEXT_USER_AGENT_KEY])

    return client


# Traceback (MetadataEndpointError)
PLAYBOOK: test.yaml ************************************************************************************************************************************************************************************************************************
1 plays in test.yaml

PLAY [localhost] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************************************************************************
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877 `" &amp;&amp; echo ansible-tmp-1512128613.81-45687956999877="` echo /root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /tmp/tmpLaEe9H TO /root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877/setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877/ /root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877/setup.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1512128613.81-45687956999877/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [localhost]
META: ran handlers

TASK [Create storage account] **************************************************************************************************************************************************************************************************************
task path: /test.yaml:4
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_storageaccount.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587 `" &amp;&amp; echo ansible-tmp-1512128614.68-124802220519587="` echo /root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587 `" ) &amp;&amp; sleep 0'
<127.0.0.1> PUT /tmp/tmpZfm_PM TO /root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587/azure_rm_storageaccount.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587/ /root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587/azure_rm_storageaccount.py &amp;&amp; sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587/azure_rm_storageaccount.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1512128614.68-124802220519587/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_CDk4HC/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 249, in __init__
self._cloud_environment = azure_cloud.get_cloud_from_metadata_endpoint(raw_cloud_env)
File "/usr/lib/python2.7/site-packages/msrestazure/azure_cloud.py", line 246, in get_cloud_from_metadata_endpoint
_populate_from_metadata_endpoint(cloud, arm_endpoint)
File "/usr/lib/python2.7/site-packages/msrestazure/azure_cloud.py", line 223, in _populate_from_metadata_endpoint
raise MetadataEndpointError(error_msg_fmt.format(msg))
MetadataEndpointError: Unable to get endpoints from the cloud.
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='management.local.azurestack.external', port=443): Max retries exceeded with url: /metadata/endpoints?api-version=2015-01-01/metadata/endpoints?api-version=2015-01-01 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

fatal: [localhost]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"access_tier": null,
"account_type": "Standard_LRS",
"ad_user": null,
"append_tags": true,
"cli_default_profile": null,
"client_id": null,
"cloud_environment": null,
"custom_domain": null,
"force": false,
"kind": "Storage",
"location": null,
"name": "testaccount001",
"password": null,
"profile": null,
"resource_group": "Testing",
"secret": null,
"state": "present",
"subscription_id": null,
"tags": null,
"tenant": null
}
},
"msg": "cloud_environment https://management.local.azurestack.external/metadata/endpoints?api-version=2015-01-01 could not be resolved: Unable to get endpoints from the cloud.\nPlease ensure you have network connection. Error detail: HTTPSConnectionPool(host='management.local.azurestack.external', port=443): Max retries exceeded with url: /metadata/endpoints?api-version=2015-01-01/metadata/endpoints?api-version=2015-01-01 (Caused by SSLError(SSLError(\"bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)\",),))"
}
to retry, use: --limit @/test.retry

PLAY RECAP *********************************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

# Fixed code
def get_mgmt_svc_client(self, client_type, base_url=None, api_version=None):
    self.log("Getting management service client {0}".format(client_type.__name__))
    self.check_client_version(client_type)
    if api_version:
        client = client_type(
            self.azure_credentials,
            self.subscription_id,
            api_version=api_version,
            base_url=base_url,
        )
    else:
        client = client_type(
            self.azure_credentials, self.subscription_id, base_url=base_url
        )

    # Add user agent for Ansible
    client.config.add_user_agent(ANSIBLE_USER_AGENT)
    # Add user agent when running from Cloud Shell
    if CLOUDSHELL_USER_AGENT_KEY in os.environ:
        client.config.add_user_agent(os.environ[CLOUDSHELL_USER_AGENT_KEY])
    # Add user agent when running from VSCode extension
    if VSCODEEXT_USER_AGENT_KEY in os.environ:
        client.config.add_user_agent(os.environ[VSCODEEXT_USER_AGENT_KEY])

    if self._cert_validation_mode == "ignore":
        client.config.session_configuration_callback = self._validation_ignore_callback

    return client