# Buggy code
def get_vrf_description(vrf, module):
    command_type = "cli_show_ascii"
    command = r"show run section vrf | begin ^vrf\scontext\s{0} | end ^vrf.*".format(
        vrf
    )

    description = ""
    descr_regex = r".*description\s(?P<descr>[\S+\s]+).*"
    body = execute_show_command(command, module, command_type)

    try:
        body = body[0]
        splitted_body = body.split("\n")
    except (AttributeError, IndexError):
        return description

    for element in splitted_body:
        if "description" in element:
            match_description = re.match(descr_regex, element, re.DOTALL)
            group_description = match_description.groupdict()
            description = group_description["descr"]

    return description


# 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_description(vrf, module):
    command = r"show run section vrf | begin ^vrf\scontext\s{0} | end ^vrf.*".format(
        vrf
    )

    description = ""
    descr_regex = r".*description\s(?P<descr>[\S+\s]+).*"
    body = execute_show_command(command, module)

    try:
        body = body[0]
        splitted_body = body.split("\n")
    except (AttributeError, IndexError):
        return description

    for element in splitted_body:
        if "description" in element:
            match_description = re.match(descr_regex, element, re.DOTALL)
            group_description = match_description.groupdict()
            description = group_description["descr"]

    return description