# Buggy code
def _load_machines(self, machines):
    for machine in machines:
        id_dict = azure_id_to_dict(machine.id)

        # TODO - The API is returning an ID value containing resource group name in ALL CAPS. If/when it gets
        #       fixed, we should remove the .lower(). Opened Issue
        #       #574: https://github.com/Azure/azure-sdk-for-python/issues/574
        resource_group = id_dict["resourceGroups"].lower()

        if self.group_by_security_group:
            self._get_security_groups(resource_group)

        host_vars = dict(
            ansible_host=None,
            private_ip=None,
            private_ip_alloc_method=None,
            public_ip=None,
            public_ip_name=None,
            public_ip_id=None,
            public_ip_alloc_method=None,
            fqdn=None,
            location=machine.location,
            name=machine.name,
            type=machine.type,
            id=machine.id,
            tags=machine.tags,
            network_interface_id=None,
            network_interface=None,
            resource_group=resource_group,
            mac_address=None,
            plan=(machine.plan.name if machine.plan else None),
            virtual_machine_size=machine.hardware_profile.vm_size,
            computer_name=(
                machine.os_profile.computer_name if machine.os_profile else None
            ),
            provisioning_state=machine.provisioning_state,
        )

        host_vars["os_disk"] = dict(
            name=machine.storage_profile.os_disk.name,
            operating_system_type=machine.storage_profile.os_disk.os_type.value,
        )

        if self.include_powerstate:
            host_vars["powerstate"] = self._get_powerstate(resource_group, machine.name)

        if machine.storage_profile.image_reference:
            host_vars["image"] = dict(
                offer=machine.storage_profile.image_reference.offer,
                publisher=machine.storage_profile.image_reference.publisher,
                sku=machine.storage_profile.image_reference.sku,
                version=machine.storage_profile.image_reference.version,
            )

        # Add windows details
        if (
            machine.os_profile is not None
            and machine.os_profile.windows_configuration is not None
        ):
            host_vars["ansible_connection"] = "winrm"
            host_vars["windows_auto_updates_enabled"] = (
                machine.os_profile.windows_configuration.enable_automatic_updates
            )
            host_vars["windows_timezone"] = (
                machine.os_profile.windows_configuration.time_zone
            )
            host_vars["windows_rm"] = None
            if machine.os_profile.windows_configuration.win_rm is not None:
                host_vars["windows_rm"] = dict(listeners=None)
                if (
                    machine.os_profile.windows_configuration.win_rm.listeners
                    is not None
                ):
                    host_vars["windows_rm"]["listeners"] = []
                    for (
                        listener
                    ) in machine.os_profile.windows_configuration.win_rm.listeners:
                        host_vars["windows_rm"]["listeners"].append(
                            dict(
                                protocol=listener.protocol.name,
                                certificate_url=listener.certificate_url,
                            )
                        )

        for interface in machine.network_profile.network_interfaces:
            interface_reference = self._parse_ref_id(interface.id)
            network_interface = self._network_client.network_interfaces.get(
                interface_reference["resourceGroups"],
                interface_reference["networkInterfaces"],
            )
            if network_interface.primary:
                if self.group_by_security_group and self._security_groups[
                    resource_group
                ].get(network_interface.id, None):
                    host_vars["security_group"] = self._security_groups[resource_group][
                        network_interface.id
                    ]["name"]
                    host_vars["security_group_id"] = self._security_groups[
                        resource_group
                    ][network_interface.id]["id"]
                host_vars["network_interface"] = network_interface.name
                host_vars["network_interface_id"] = network_interface.id
                host_vars["mac_address"] = network_interface.mac_address
                for ip_config in network_interface.ip_configurations:
                    host_vars["private_ip"] = ip_config.private_ip_address
                    host_vars["private_ip_alloc_method"] = (
                        ip_config.private_ip_allocation_method
                    )
                    if self.use_private_ip:
                        host_vars["ansible_host"] = ip_config.private_ip_address
                    if ip_config.public_ip_address:
                        public_ip_reference = self._parse_ref_id(
                            ip_config.public_ip_address.id
                        )
                        public_ip_address = (
                            self._network_client.public_ip_addresses.get(
                                public_ip_reference["resourceGroups"],
                                public_ip_reference["publicIPAddresses"],
                            )
                        )
                        if not self.use_private_ip:
                            host_vars["ansible_host"] = public_ip_address.ip_address
                        host_vars["public_ip"] = public_ip_address.ip_address
                        host_vars["public_ip_name"] = public_ip_address.name
                        host_vars["public_ip_alloc_method"] = (
                            public_ip_address.public_ip_allocation_method
                        )
                        host_vars["public_ip_id"] = public_ip_address.id
                        if public_ip_address.dns_settings:
                            host_vars["fqdn"] = public_ip_address.dns_settings.fqdn

        self._add_host(host_vars)


# 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 _load_machines(self, machines):
    for machine in machines:
        id_dict = azure_id_to_dict(machine.id)

        # TODO - The API is returning an ID value containing resource group name in ALL CAPS. If/when it gets
        #       fixed, we should remove the .lower(). Opened Issue
        #       #574: https://github.com/Azure/azure-sdk-for-python/issues/574
        resource_group = id_dict["resourceGroups"].lower()

        if self.group_by_security_group:
            self._get_security_groups(resource_group)

        host_vars = dict(
            ansible_host=None,
            private_ip=None,
            private_ip_alloc_method=None,
            public_ip=None,
            public_ip_name=None,
            public_ip_id=None,
            public_ip_alloc_method=None,
            fqdn=None,
            location=machine.location,
            name=machine.name,
            type=machine.type,
            id=machine.id,
            tags=machine.tags,
            network_interface_id=None,
            network_interface=None,
            resource_group=resource_group,
            mac_address=None,
            plan=(machine.plan.name if machine.plan else None),
            virtual_machine_size=machine.hardware_profile.vm_size,
            computer_name=(
                machine.os_profile.computer_name if machine.os_profile else None
            ),
            provisioning_state=machine.provisioning_state,
        )

        host_vars["os_disk"] = dict(
            name=machine.storage_profile.os_disk.name,
            operating_system_type=machine.storage_profile.os_disk.os_type.value.lower(),
        )

        if self.include_powerstate:
            host_vars["powerstate"] = self._get_powerstate(resource_group, machine.name)

        if machine.storage_profile.image_reference:
            host_vars["image"] = dict(
                offer=machine.storage_profile.image_reference.offer,
                publisher=machine.storage_profile.image_reference.publisher,
                sku=machine.storage_profile.image_reference.sku,
                version=machine.storage_profile.image_reference.version,
            )

        # Add windows details
        if (
            machine.os_profile is not None
            and machine.os_profile.windows_configuration is not None
        ):
            host_vars["ansible_connection"] = "winrm"
            host_vars["windows_auto_updates_enabled"] = (
                machine.os_profile.windows_configuration.enable_automatic_updates
            )
            host_vars["windows_timezone"] = (
                machine.os_profile.windows_configuration.time_zone
            )
            host_vars["windows_rm"] = None
            if machine.os_profile.windows_configuration.win_rm is not None:
                host_vars["windows_rm"] = dict(listeners=None)
                if (
                    machine.os_profile.windows_configuration.win_rm.listeners
                    is not None
                ):
                    host_vars["windows_rm"]["listeners"] = []
                    for (
                        listener
                    ) in machine.os_profile.windows_configuration.win_rm.listeners:
                        host_vars["windows_rm"]["listeners"].append(
                            dict(
                                protocol=listener.protocol.name,
                                certificate_url=listener.certificate_url,
                            )
                        )

        for interface in machine.network_profile.network_interfaces:
            interface_reference = self._parse_ref_id(interface.id)
            network_interface = self._network_client.network_interfaces.get(
                interface_reference["resourceGroups"],
                interface_reference["networkInterfaces"],
            )
            if network_interface.primary:
                if self.group_by_security_group and self._security_groups[
                    resource_group
                ].get(network_interface.id, None):
                    host_vars["security_group"] = self._security_groups[resource_group][
                        network_interface.id
                    ]["name"]
                    host_vars["security_group_id"] = self._security_groups[
                        resource_group
                    ][network_interface.id]["id"]
                host_vars["network_interface"] = network_interface.name
                host_vars["network_interface_id"] = network_interface.id
                host_vars["mac_address"] = network_interface.mac_address
                for ip_config in network_interface.ip_configurations:
                    host_vars["private_ip"] = ip_config.private_ip_address
                    host_vars["private_ip_alloc_method"] = (
                        ip_config.private_ip_allocation_method
                    )
                    if self.use_private_ip:
                        host_vars["ansible_host"] = ip_config.private_ip_address
                    if ip_config.public_ip_address:
                        public_ip_reference = self._parse_ref_id(
                            ip_config.public_ip_address.id
                        )
                        public_ip_address = (
                            self._network_client.public_ip_addresses.get(
                                public_ip_reference["resourceGroups"],
                                public_ip_reference["publicIPAddresses"],
                            )
                        )
                        if not self.use_private_ip:
                            host_vars["ansible_host"] = public_ip_address.ip_address
                        host_vars["public_ip"] = public_ip_address.ip_address
                        host_vars["public_ip_name"] = public_ip_address.name
                        host_vars["public_ip_alloc_method"] = (
                            public_ip_address.public_ip_allocation_method
                        )
                        host_vars["public_ip_id"] = public_ip_address.id
                        if public_ip_address.dns_settings:
                            host_vars["fqdn"] = public_ip_address.dns_settings.fqdn

        self._add_host(host_vars)