# Buggy code
def parse_interfaces(module, vlan):
    vlan_int = []
    interfaces = vlan.get("vlanshowplist-ifidx")
    if interfaces:
        for i in interfaces.split(","):
            if "-" in i:
                int_range = i.split("-")
                stop = int((int_range)[1])
                start = int(int_range[0].split("/")[1])
                eth = int_range[0].split("/")[0]
                for r in range(start, stop + 1):
                    vlan_int.append(eth + "/" + str(r))
            else:
                vlan_int.append(i)

    return vlan_int


# Traceback (ValueError)
TASK [nxos_l2_interface : Setup vlans] **************************************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_l2_interface/tests/common/sanity.yaml:24
<n9k.example.com> attempting to start connection
<n9k.example.com> using connection plugin network_cli
<n9k.example.com> found existing local domain socket, using it!
<n9k.example.com> updating play_context for connection
<n9k.example.com>
<n9k.example.com> local domain socket path is /Users/mwiebe/.ansible/pc/351688cc74
Using module file /Users/mwiebe/Projects/nxos_ansible/fix_ansible/lib/ansible/modules/network/nxos/nxos_vlan.py
<n9k.example.com> ESTABLISH LOCAL CONNECTION FOR USER: mwiebe
<n9k.example.com> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<n9k.example.com> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/mwiebe/.ansible/tmp/ansible-tmp-1517336665.05-60551152859800 `" &amp;&amp; echo ansible-tmp-1517336665.05-60551152859800="` echo /Users/mwiebe/.ansible/tmp/ansible-tmp-1517336665.05-60551152859800 `" ) &amp;&amp; sleep 0'
<n9k.example.com> PUT /Users/mwiebe/.ansible/tmp/ansible-local-31740vNIr34/tmpAfL577 TO /Users/mwiebe/.ansible/tmp/ansible-tmp-1517336665.05-60551152859800/nxos_vlan.py
<n9k.example.com> EXEC /bin/sh -c 'chmod u+x /Users/mwiebe/.ansible/tmp/ansible-tmp-1517336665.05-60551152859800/ /Users/mwiebe/.ansible/tmp/ansible-tmp-1517336665.05-60551152859800/nxos_vlan.py &amp;&amp; sleep 0'
<n9k.example.com> EXEC /bin/sh -c '/Users/mwiebe/Virtualenvs/py2-ansible/bin/python /Users/mwiebe/.ansible/tmp/ansible-tmp-1517336665.05-60551152859800/nxos_vlan.py &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py", line 535, in <module>
main()
File "/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py", line 514, in main
have = map_config_to_obj(module, os_platform)
File "/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py", line 448, in map_config_to_obj
obj = parse_vlan_options(module, os_platform, output, vlans)
File "/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py", line 429, in parse_vlan_options
obj['interfaces'] = parse_interfaces(module, vlan)
File "/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py", line 409, in parse_interfaces
stop = int((int_range)[1])
ValueError: invalid literal for int() with base 10: 'channel10'

fatal: [n9k.example.com]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py\", line 535, in <module>\n    main()\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py\", line 514, in main\n    have = map_config_to_obj(module, os_platform)\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py\", line 448, in map_config_to_obj\n    obj = parse_vlan_options(module, os_platform, output, vlans)\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py\", line 429, in parse_vlan_options\n    obj['interfaces'] = parse_interfaces(module, vlan)\n  File \"/var/folders/ww/538d42ys18l5tjyz0l1yk1rc0000gn/T/ansible_3pxmTt/ansible_module_nxos_vlan.py\", line 409, in parse_interfaces\n    stop = int((int_range)[1])\nValueError: invalid literal for int() with base 10: 'channel10'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
to retry, use: --limit @/Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/nxos.retry

PLAY RECAP ******************************************************************************************************************************************************************************************************************
n9k.example.com        : ok=26   changed=2    unreachable=0    failed=1

# Fixed code
def parse_interfaces(module, vlan):
    vlan_int = []
    interfaces = vlan.get("vlanshowplist-ifidx")
    if interfaces:
        for i in interfaces.split(","):
            if "eth" in i.lower() and "-" in i:
                int_range = i.split("-")
                stop = int((int_range)[1])
                start = int(int_range[0].split("/")[1])
                eth = int_range[0].split("/")[0]
                for r in range(start, stop + 1):
                    vlan_int.append(eth + "/" + str(r))
            else:
                vlan_int.append(i)

    return vlan_int