# Buggy code
def deploy_template(self):
    """
    Deploy the targeted template and parameters
    :param module: Ansible module containing the validated configuration for the deployment template
    :param client: resource management client for azure
    :param conn_info: connection info needed
    :return:
    """

    deploy_parameter = self.rm_models.DeploymentProperties(self.deployment_mode)
    if not self.parameters_link:
        deploy_parameter.parameters = self.parameters
    else:
        deploy_parameter.parameters_link = self.rm_models.ParametersLink(
            uri=self.parameters_link
        )
    if not self.template_link:
        deploy_parameter.template = self.template
    else:
        deploy_parameter.template_link = self.rm_models.TemplateLink(
            uri=self.template_link
        )

    params = self.rm_models.ResourceGroup(location=self.location, tags=self.tags)

    try:
        self.rm_client.resource_groups.create_or_update(
            self.resource_group_name, params
        )
    except CloudError as exc:
        self.fail(
            "Resource group create_or_update failed with status code: %s and message: %s"
            % (exc.status_code, exc.message)
        )
    try:
        result = self.rm_client.deployments.create_or_update(
            self.resource_group_name, self.deployment_name, deploy_parameter
        )

        deployment_result = None
        if self.wait_for_deployment_completion:
            deployment_result = self.get_poller_result(result)
            while (
                deployment_result.properties is None
                or deployment_result.properties.provisioning_state
                not in ["Canceled", "Failed", "Deleted", "Succeeded"]
            ):
                time.sleep(self.wait_for_deployment_polling_period)
                deployment_result = self.rm_client.deployments.get(
                    self.resource_group_name, self.deployment_name
                )
    except CloudError as exc:
        failed_deployment_operations = self._get_failed_deployment_operations(
            self.deployment_name
        )
        self.log("Deployment failed %s: %s" % (exc.status_code, exc.message))
        self.fail(
            "Deployment failed with status code: %s and message: %s"
            % (exc.status_code, exc.message),
            failed_deployment_operations=failed_deployment_operations,
        )

    if (
        self.wait_for_deployment_completion
        and deployment_result.properties.provisioning_state != "Succeeded"
    ):
        self.log(
            "provisioning state: %s" % deployment_result.properties.provisioning_state
        )
        failed_deployment_operations = self._get_failed_deployment_operations(
            self.deployment_name
        )
        self.fail(
            "Deployment failed. Deployment id: %s" % deployment_result.id,
            failed_deployment_operations=failed_deployment_operations,
        )

    return deployment_result


# Traceback (TypeError)
TASK [azure_load_balancer : Get lbs] *********************************************************************************************
task path: /home/vmadmin/cluster_build/roles/azure_load_balancer/tasks/main.yaml:15
Using module file /home/vmadmin/.local/lib/python2.7/site-packages/ansible/modules/cloud/azure/azure_rm_loadbalancer_facts.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: vmadmin
<localhost> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814 `" &amp;&amp; echo ansible-tmp-1504708358.3-41710485333814="` echo /home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814 `" ) &amp;&amp; sleep 0'
<localhost> PUT /tmp/tmpy_CiqC TO /home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814/azure_rm_loadbalancer_facts.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814/ /home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814/azure_rm_loadbalancer_facts.py &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814/azure_rm_loadbalancer_facts.py; rm -rf "/home/vmadmin/.ansible/tmp/ansible-tmp-1504708358.3-41710485333814/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py", line 180, in <module>
main()
File "/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py", line 177, in main
AzureRMLoadBalancerFacts()
File "/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py", line 123, in __init__
facts_module=True
File "/tmp/ansible_VTaHxN/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py", line 255, in __init__
File "/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py", line 133, in exec_module
else self.list_items()
File "/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py", line 162, in list_items
response = self.network_client.load_balancers.list()
TypeError: list() takes at least 2 arguments (1 given)

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py\", line 180, in <module>\n    main()\n  File \"/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py\", line 177, in main\n    AzureRMLoadBalancerFacts()\n  File \"/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py\", line 123, in __init__\n    facts_module=True\n  File \"/tmp/ansible_VTaHxN/ansible_modlib.zip/ansible/module_utils/azure_rm_common.py\", line 255, in __init__\n  File \"/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py\", line 133, in exec_module\n    else self.list_items()\n  File \"/tmp/ansible_VTaHxN/ansible_module_azure_rm_loadbalancer_facts.py\", line 162, in list_items\n    response = self.network_client.load_balancers.list()\nTypeError: list() takes at least 2 arguments (1 given)\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def deploy_template(self):
    """
    Deploy the targeted template and parameters
    :param module: Ansible module containing the validated configuration for the deployment template
    :param client: resource management client for azure
    :param conn_info: connection info needed
    :return:
    """

    deploy_parameter = self.rm_models.DeploymentProperties(self.deployment_mode)
    if not self.parameters_link:
        deploy_parameter.parameters = self.parameters
    else:
        deploy_parameter.parameters_link = self.rm_models.ParametersLink(
            uri=self.parameters_link
        )
    if not self.template_link:
        deploy_parameter.template = self.template
    else:
        deploy_parameter.template_link = self.rm_models.TemplateLink(
            uri=self.template_link
        )

    if self.append_tags and self.tags:
        try:
            rg = self.get_resource_group(self.resource_group_name)
            if rg.tags:
                self.tags = dict(self.tags, **rg.tags)
        except CloudError:
            # resource group does not exist
            pass

    params = self.rm_models.ResourceGroup(location=self.location, tags=self.tags)

    try:
        self.rm_client.resource_groups.create_or_update(
            self.resource_group_name, params
        )
    except CloudError as exc:
        self.fail(
            "Resource group create_or_update failed with status code: %s and message: %s"
            % (exc.status_code, exc.message)
        )
    try:
        result = self.rm_client.deployments.create_or_update(
            self.resource_group_name, self.deployment_name, deploy_parameter
        )

        deployment_result = None
        if self.wait_for_deployment_completion:
            deployment_result = self.get_poller_result(result)
            while (
                deployment_result.properties is None
                or deployment_result.properties.provisioning_state
                not in ["Canceled", "Failed", "Deleted", "Succeeded"]
            ):
                time.sleep(self.wait_for_deployment_polling_period)
                deployment_result = self.rm_client.deployments.get(
                    self.resource_group_name, self.deployment_name
                )
    except CloudError as exc:
        failed_deployment_operations = self._get_failed_deployment_operations(
            self.deployment_name
        )
        self.log("Deployment failed %s: %s" % (exc.status_code, exc.message))
        self.fail(
            "Deployment failed with status code: %s and message: %s"
            % (exc.status_code, exc.message),
            failed_deployment_operations=failed_deployment_operations,
        )

    if (
        self.wait_for_deployment_completion
        and deployment_result.properties.provisioning_state != "Succeeded"
    ):
        self.log(
            "provisioning state: %s" % deployment_result.properties.provisioning_state
        )
        failed_deployment_operations = self._get_failed_deployment_operations(
            self.deployment_name
        )
        self.fail(
            "Deployment failed. Deployment id: %s" % deployment_result.id,
            failed_deployment_operations=failed_deployment_operations,
        )

    return deployment_result