# Buggy code
def get_vrf(vrf, module):
    command = "show vrf {0}".format(vrf)
    vrf_key = {"vrf_name": "vrf", "vrf_state": "admin_state"}

    body = execute_show_command(command, module)
    try:
        vrf_table = body[0]["TABLE_vrf"]["ROW_vrf"]
    except (TypeError, IndexError):
        return {}

    parsed_vrf = apply_key_map(vrf_key, vrf_table)

    command = "show run all | section vrf.context.{0}".format(vrf)
    body = execute_show_command(command, module, "cli_show_ascii")
    extra_params = ["vni", "rd", "description"]
    for param in extra_params:
        parsed_vrf[param] = get_value(param, body[0], module)

    return parsed_vrf


# Traceback (TypeError)
ubuntu@ubuntu-xenial:/vagrant/ansible-nxos$ ansible-playbook -i hosts test1.yml -u cisco -k
SSH password:

PLAY [vlan testing] ************************************************************************************************************************************************************************************************************************************************


TASK [Create vrfs] *************************************************************************************************************************************************************************************************************************************************

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object has no attribute '__getitem__'
fatal: [sp2]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf.py\", line 326, in <module>\n    main()\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf
.py\", line 269, in main\n    existing = get_vrf(vrf, module)\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf.py\", line 215, in get_vrf\n    body = execute_show_command(command, module)\n  File \"/tmp/ansible_BBb2AR/ansible_module_nxos_vrf.py\", line 12
9, in execute_show_command\n    transport = module.params['provider']['transport']\nTypeError: 'NoneType' object has no attribute '__getitem__'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: 'NoneType' object has no attribute '__getitem__'
fatal: [sp1]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf.py\", line 326, in <module>\n    main()\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf
.py\", line 269, in main\n    existing = get_vrf(vrf, module)\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf.py\", line 215, in get_vrf\n    body = execute_show_command(command, module)\n  File \"/tmp/ansible_4Mqx2r/ansible_module_nxos_vrf.py\", line 12
9, in execute_show_command\n    transport = module.params['provider']['transport']\nTypeError: 'NoneType' object has no attribute '__getitem__'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}
to retry, use: --limit @/vagrant/ansible-nxos/test1.retry

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************

sp1                        : ok=0    changed=0    unreachable=0    failed=1
sp2                        : ok=0    changed=0    unreachable=0    failed=1

--------

It looks like although provider is an optional parameter, it is required in configuration because of line 129 in source code.

# Fixed code
def get_vrf(vrf, module):
    command = "show vrf {0}".format(vrf)
    vrf_key = {"vrf_name": "vrf", "vrf_state": "admin_state"}

    body = execute_show_command(command, module)
    try:
        vrf_table = body[0]["TABLE_vrf"]["ROW_vrf"]
    except (TypeError, IndexError):
        return {}

    parsed_vrf = apply_key_map(vrf_key, vrf_table)

    command = "show run all | section vrf.context.{0}".format(vrf)
    body = execute_show_command(command, module)
    extra_params = ["vni", "rd", "description"]
    for param in extra_params:
        parsed_vrf[param] = get_value(param, body[0], module)

    return parsed_vrf