# Buggy code
def main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        description=dict(type="str", aliases=["descr"]),
        node_id=dict(type="int"),  # Not required for querying all objects
        pod_id=dict(type="int"),
        role=dict(
            type="str", choices=["leaf", "spine", "unspecified"], aliases=["role_name"]
        ),
        serial=dict(
            type="str", aliases=["serial_number"]
        ),  # Not required for querying all objects
        switch=dict(type="str", aliases=["name", "switch_name"]),
        state=dict(
            type="str", default="present", choices=["absent", "present", "query"]
        ),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["node_id", "serial"]],
            ["state", "present", ["node_id", "serial"]],
        ],
    )

    pod_id = module.params["pod_id"]
    serial = module.params["serial"]
    node_id = module.params["node_id"]
    switch = module.params["switch"]
    description = module.params["description"]
    role = module.params["role"]
    state = module.params["state"]

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class="fabricNodeIdentP",
            aci_rn="controller/nodeidentpol/nodep-{0}".format(serial),
            module_object=serial,
            target_filter={"serial": serial},
        )
    )

    aci.get_existing()

    if state == "present":
        aci.payload(
            aci_class="fabricNodeIdentP",
            class_config=dict(
                descr=description,
                name=switch,
                nodeId=node_id,
                podId=pod_id,
                rn="nodep-{0}".format(serial),
                role=role,
                serial=serial,
            ),
        )

        aci.get_diff(aci_class="fabricNodeIdentP")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json(**aci.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 main():
    argument_spec = aci_argument_spec()
    argument_spec.update(
        description=dict(type="str", aliases=["descr"]),
        node_id=dict(type="int"),  # Not required for querying all objects
        pod_id=dict(type="int"),
        role=dict(
            type="str", choices=["leaf", "spine", "unspecified"], aliases=["role_name"]
        ),
        serial=dict(
            type="str", aliases=["serial_number"]
        ),  # Not required for querying all objects
        switch=dict(type="str", aliases=["name", "switch_name"]),
        state=dict(
            type="str", default="present", choices=["absent", "present", "query"]
        ),
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
        supports_check_mode=True,
        required_if=[
            ["state", "absent", ["node_id", "serial"]],
            ["state", "present", ["node_id", "serial"]],
        ],
    )

    pod_id = module.params["pod_id"]
    serial = module.params["serial"]
    node_id = module.params["node_id"]
    switch = module.params["switch"]
    description = module.params["description"]
    role = module.params["role"]
    state = module.params["state"]

    aci = ACIModule(module)
    aci.construct_url(
        root_class=dict(
            aci_class="fabricNodeIdentP",
            aci_rn="controller/nodeidentpol/nodep-{0}".format(serial),
            module_object=serial,
            target_filter={"serial": serial},
        )
    )

    aci.get_existing()

    if state == "present":
        aci.payload(
            aci_class="fabricNodeIdentP",
            class_config=dict(
                descr=description,
                name=switch,
                nodeId=node_id,
                podId=pod_id,
                # NOTE: Originally we were sending 'rn', but now we need 'dn' for idempotency
                # FIXME: Did this change with ACI version ?
                dn="uni/controller/nodeidentpol/nodep-{0}".format(serial),
                # rn='nodep-{0}'.format(serial),
                role=role,
                serial=serial,
            ),
        )

        aci.get_diff(aci_class="fabricNodeIdentP")

        aci.post_config()

    elif state == "absent":
        aci.delete_config()

    aci.exit_json(**aci.result)