# Buggy code
def check_declarative_intent_params(self):
    failed_conditions = []
    for want_item in self._want:
        want_state = want_item.get("state")
        want_tx_rate = want_item.get("tx_rate")
        want_rx_rate = want_item.get("rx_rate")
        if want_state not in ("up", "down") and not want_tx_rate and not want_rx_rate:
            continue

        if self._result["changed"]:
            sleep(want_item["delay"])

        command = "show interfaces {!s}".format(want_item["name"])
        out = run_command(self._module, command)[0]

        if want_state in ("up", "down"):
            match = re.search(r"%s (\w+)" % "line protocol is", out, re.M)
            have_state = None
            if match:
                have_state = match.group(1)
                if have_state.strip() == "administratively":
                    match = re.search(r"%s (\w+)" % "administratively", out, re.M)
                    if match:
                        have_state = match.group(1)

            if have_state is None or not conditional(want_state, have_state.strip()):
                failed_conditions.append("state " + "eq({!s})".format(want_state))

        if want_tx_rate:
            match = re.search(r"%s (\d+)" % "output rate", out, re.M)
            have_tx_rate = None
            if match:
                have_tx_rate = match.group(1)

            if have_tx_rate is None or not conditional(
                want_tx_rate, have_tx_rate.strip(), cast=int
            ):
                failed_conditions.append("tx_rate " + want_tx_rate)

        if want_rx_rate:
            match = re.search(r"%s (\d+)" % "input rate", out, re.M)
            have_rx_rate = None
            if match:
                have_rx_rate = match.group(1)

            if have_rx_rate is None or not conditional(
                want_rx_rate, have_rx_rate.strip(), cast=int
            ):
                failed_conditions.append("rx_rate " + want_rx_rate)

    if failed_conditions:
        msg = "One or more conditional statements have not been satisfied"
        self._module.fail_json(msg=msg, failed_conditions=failed_conditions)


# 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 check_declarative_intent_params(self):
    failed_conditions = []
    for want_item in self._want:
        want_state = want_item.get("state")
        want_tx_rate = want_item.get("tx_rate")
        want_rx_rate = want_item.get("rx_rate")
        if want_state not in ("up", "down") and not want_tx_rate and not want_rx_rate:
            continue

        if self._result["changed"]:
            sleep(want_item["delay"])

        command = "show interfaces {!s}".format(want_item["name"])
        out = run_commands(self._module, command)[0]

        if want_state in ("up", "down"):
            match = re.search(r"%s (\w+)" % "line protocol is", out, re.M)
            have_state = None
            if match:
                have_state = match.group(1)
                if have_state.strip() == "administratively":
                    match = re.search(r"%s (\w+)" % "administratively", out, re.M)
                    if match:
                        have_state = match.group(1)

            if have_state is None or not conditional(want_state, have_state.strip()):
                failed_conditions.append("state " + "eq({!s})".format(want_state))

        if want_tx_rate:
            match = re.search(r"%s (\d+)" % "output rate", out, re.M)
            have_tx_rate = None
            if match:
                have_tx_rate = match.group(1)

            if have_tx_rate is None or not conditional(
                want_tx_rate, have_tx_rate.strip(), cast=int
            ):
                failed_conditions.append("tx_rate " + want_tx_rate)

        if want_rx_rate:
            match = re.search(r"%s (\d+)" % "input rate", out, re.M)
            have_rx_rate = None
            if match:
                have_rx_rate = match.group(1)

            if have_rx_rate is None or not conditional(
                want_rx_rate, have_rx_rate.strip(), cast=int
            ):
                failed_conditions.append("rx_rate " + want_rx_rate)

    if failed_conditions:
        msg = "One or more conditional statements have not been satisfied"
        self._module.fail_json(msg=msg, failed_conditions=failed_conditions)