# Buggy code
def map_obj_to_commands(updates):
    commands = list()
    want, have = updates

    for w in want:
        state = w["state"]
        del w["state"]

        if state == "absent" and w in have:
            if w["facility"] is not None:
                if not w["dest"]:
                    commands.append("no logging level {}".format(w["facility"]))

            if w["name"] is not None:
                commands.append("no logging logfile")

            if w["dest"] in ("console", "module", "monitor"):
                commands.append("no logging {}".format(w["dest"]))

            if w["dest"] == "server":
                commands.append("no logging server {}".format(w["remote_server"]))

        if state == "present" and w not in have:
            if w["facility"] is None:
                if w["dest"]:
                    if w["dest"] not in ("logfile", "server"):
                        commands.append(
                            "logging {} {}".format(w["dest"], w["dest_level"])
                        )

                    elif w["dest"] == "logfile":
                        commands.append(
                            "logging logfile {} {}".format(w["name"], w["dest_level"])
                        )

                    elif w["dest"] == "server":
                        if w["dest_level"]:
                            commands.append(
                                "logging server {0} {1}".format(
                                    w["remote_server"], w["dest_level"]
                                )
                            )
                        else:
                            commands.append(
                                "logging server {0}".format(w["remote_server"])
                            )
                    else:
                        pass

            if w["facility"]:
                if w["dest"] == "server":
                    if w["dest_level"]:
                        commands.append(
                            "logging server {0} {1} facility {2}".format(
                                w["remote_server"], w["dest_level"], w["facility"]
                            )
                        )
                    else:
                        commands.append(
                            "logging server {0} facility {1}".format(
                                w["remote_server"], w["facility"]
                            )
                        )
                else:
                    commands.append(
                        "logging level {} {}".format(w["facility"], w["facility_level"])
                    )

    return commands


# 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 map_obj_to_commands(updates):
    commands = list()
    want, have = updates

    for w in want:
        state = w["state"]
        del w["state"]

        if state == "absent" and w in have:
            if w["facility"] is not None:
                if not w["dest"]:
                    commands.append("no logging level {}".format(w["facility"]))

            if w["name"] is not None:
                commands.append("no logging logfile")

            if w["dest"] in ("console", "module", "monitor"):
                commands.append("no logging {}".format(w["dest"]))

            if w["dest"] == "server":
                commands.append("no logging server {}".format(w["remote_server"]))

            if w["interface_type"]:
                commands.append("no logging source-interface")

        if state == "present" and w not in have:
            if w["facility"] is None:
                if w["dest"]:
                    if w["dest"] not in ("logfile", "server"):
                        commands.append(
                            "logging {} {}".format(w["dest"], w["dest_level"])
                        )

                    elif w["dest"] == "logfile":
                        commands.append(
                            "logging logfile {} {}".format(w["name"], w["dest_level"])
                        )

                    elif w["dest"] == "server":
                        if w["facility_level"]:
                            if w["use_vrf"]:
                                commands.append(
                                    "logging server {0} {1} use-vrf {2}".format(
                                        w["remote_server"],
                                        w["facility_level"],
                                        w["use_vrf"],
                                    )
                                )
                            else:
                                commands.append(
                                    "logging server {0} {1}".format(
                                        w["remote_server"], w["facility_level"]
                                    )
                                )

                        else:
                            if w["use_vrf"]:
                                commands.append(
                                    "logging server {0} use-vrf {1}".format(
                                        w["remote_server"], w["use_vrf"]
                                    )
                                )
                            else:
                                commands.append(
                                    "logging server {0}".format(w["remote_server"])
                                )

            if w["facility"]:
                if w["dest"] == "server":
                    if w["facility_level"]:
                        if w["use_vrf"]:
                            commands.append(
                                "logging server {0} {1} facility {2} use-vrf {3}".format(
                                    w["remote_server"],
                                    w["facility_level"],
                                    w["facility"],
                                    w["use_vrf"],
                                )
                            )
                        else:
                            commands.append(
                                "logging server {0} {1} facility {2}".format(
                                    w["remote_server"],
                                    w["facility_level"],
                                    w["facility"],
                                )
                            )
                    else:
                        if w["use_vrf"]:
                            commands.append(
                                "logging server {0} facility {1} use-vrf {2}".format(
                                    w["remote_server"], w["facility"], w["use_vrf"]
                                )
                            )
                        else:
                            commands.append(
                                "logging server {0} facility {1}".format(
                                    w["remote_server"], w["facility"]
                                )
                            )
                else:
                    commands.append(
                        "logging level {} {}".format(w["facility"], w["facility_level"])
                    )

            if w["interface_type"]:
                commands.append(
                    "logging source-interface {0} {1}".format(
                        w["interface_type"], w["interface"]
                    )
                )
    return commands