# Buggy code
def parse_rpcs(module):
    items = list()

    for rpc in module.params["rpcs"] or list():
        parts = split(rpc)

        name = parts.pop(0)
        args = dict()

        for item in parts:
            key, value = item.split("=")
            if str(value).upper() in ["TRUE", "FALSE"]:
                args[key] = bool(value)
            elif re.match(r"^[0-9]+$", value):
                args[key] = int(value)
            else:
                args[key] = str(value)

        display = module.params["display"] or "xml"
        xattrs = {"format": display}

        items.append({"name": name, "args": args, "xattrs": xattrs})

    return items


# Traceback (AttributeError)
$ ansible-playbook dev-conf.yml --extra-vars "dev=athens os=juniper" -vvvv
Using /home/app/saint/ansible/ansible.cfg as config file
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: dev-conf.yml *******************************************************************************************************************************
1 plays in dev-conf.yml

PLAY [dev-conf] **************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************
Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: app
<localhost> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618 `" &amp;&amp; echo ansible-tmp-1499090338.08-16740590805618="` echo /home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618 `" ) &amp;&amp; sleep 0'
<localhost> PUT /tmp/tmpMTpD5T TO /home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618/setup.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618/ /home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618/setup.py &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618/setup.py; rm -rf "/home/app/.ansible/tmp/ansible-tmp-1499090338.08-16740590805618/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
ok: [localhost]
META: ran handlers

TASK [Retrieve router's configuration: junos] ********************************************************************************************************
task path: /home/app/saint/ansible/dev-conf.yml:12
<athens> using connection plugin netconf
<athens> socket_path: /home/app/.ansible/pc/d090e15c31
open_session() returned 0 ok
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/junos/junos_command.py
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: app
<localhost> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596 `" &amp;&amp; echo ansible-tmp-1499090340.43-6328802200596="` echo /home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596 `" ) &amp;&amp; sleep 0'
<localhost> PUT /tmp/tmpGOR9Z2 TO /home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596/junos_command.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596/ /home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596/junos_command.py &amp;&amp; sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596/junos_command.py; rm -rf "/home/app/.ansible/tmp/ansible-tmp-1499090340.43-6328802200596/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_t7Cbbz/ansible_module_junos_command.py", line 388, in <module>
main()
File "/tmp/ansible_t7Cbbz/ansible_module_junos_command.py", line 338, in main
responses = rpc(module, items)
File "/tmp/ansible_t7Cbbz/ansible_module_junos_command.py", line 229, in rpc
responses.append(data.text.strip())
AttributeError: 'NoneType' object has no attribute 'text'

fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_t7Cbbz/ansible_module_junos_command.py\", line 388, in <module>\n    main()\n  File \"/tmp/ansible_t7Cbbz/ansible_module_junos_command.py\", line 338, in main\n    responses = rpc(module, items)\n  File \"/tmp/ansible_t7Cbbz/ansible_module_junos_command.py\", line 229, in rpc\n    responses.append(data.text.strip())\nAttributeError: 'NoneType' object has no attribute 'text'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}
to retry, use: --limit @/home/app/saint/ansible/dev-conf.retry

PLAY RECAP *******************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1

# Fixed code
def parse_rpcs(module):
    items = list()

    for rpc in module.params["rpcs"] or list():
        parts = split(rpc)

        name = parts.pop(0)
        args = dict()

        for item in parts:
            key, value = item.split("=")
            if str(value).upper() in ["TRUE", "FALSE"]:
                args[key] = bool(value)
            elif re.match(r"^[0-9]+$", value):
                args[key] = int(value)
            else:
                args[key] = str(value)

        display = module.params["display"] or "xml"

        if display == "set" and rpc != "get-configuration":
            module.fail_json(
                msg="Invalid display option '%s' given for rpc '%s'" % ("set", name)
            )

        xattrs = {"format": display}
        items.append({"name": name, "args": args, "xattrs": xattrs})

    return items