# Buggy code
def get_value(arg, config, module):
    custom = [
        "ospf",
        "area",
        "message_digest_key_id",
        "message_digest_algorithm_type",
        "message_digest_encryption_type",
        "message_digest_password",
        "passive_interface",
    ]

    if arg in custom:
        value = get_custom_value(arg, config, module)
    elif arg in BOOL_PARAMS:
        REGEX = re.compile(r"\s+{0}\s*$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M)
        value = False
        try:
            if REGEX.search(config):
                value = True
        except TypeError:
            value = False
    else:
        REGEX = re.compile(
            r"(?:{0}\s)(?P<value>.*)$".format(PARAM_TO_COMMAND_KEYMAP[arg]), re.M
        )
        value = ""
        if PARAM_TO_COMMAND_KEYMAP[arg] in config:
            value = REGEX.search(config).group("value")
    return value


# Traceback (TypeError)
ansible-playbook site.yml -l core7k-a --check -t configure_interface_ospf -vvv

PLAYBOOK: site.yml *************************************************************************************************************************
2 plays in site.yml

PLAY [localhost] ***************************************************************************************************************************
skipping: no hosts matched

PLAY [nxos] ********************************************************************************************************************************
META: ran handlers

TASK [configure interface ospf] ************************************************************************************************************
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_9nZ5Pe/ansible_module_nxos_interface_ospf.py", line 540, in <module>
main()
File "/tmp/ansible_9nZ5Pe/ansible_module_nxos_interface_ospf.py", line 523, in main
result.update(response)
TypeError: 'NoneType' object is not iterable

fatal: [core7k-a]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_9nZ5Pe/ansible_module_nxos_interface_ospf.py\", line 540, in <module>\n    main()\n  File \"/tmp/ansible_9nZ5Pe/ansible_module_nxos_interface_ospf.py\", line 523, in main\n    result.update(response)\nTypeError: 'NoneType' object is not iterable\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

PLAY RECAP *********************************************************************************************************************************
core7k-a               : ok=0    changed=0    unreachable=0    failed=1

# Fixed code
def get_value(arg, config, module):
    command = PARAM_TO_COMMAND_KEYMAP[arg]
    has_command = re.search(r"\s+{0}\s*$".format(command), config, re.M)
    has_command_val = re.search(
        r"(?:{0}\s)(?P<value>.*)$".format(command), config, re.M
    )

    if command == "ip router ospf":
        value = ""
        if has_command_val:
            value_list = has_command_val.group("value").split()
            if arg == "ospf":
                value = value_list[0]
            elif arg == "area":
                value = value_list[2]
    elif command == "ip ospf message-digest-key":
        value = ""
        if has_command_val:
            value_list = has_command_val.group("value").split()
            if arg == "message_digest_key_id":
                value = value_list[0]
            elif arg == "message_digest_algorithm_type":
                value = value_list[1]
            elif arg == "message_digest_encryption_type":
                value = value_list[2]
                if value == "3":
                    value = "3des"
                elif value == "7":
                    value = "cisco_type_7"
            elif arg == "message_digest_password":
                value = value_list[3]
    elif arg == "passive_interface":
        has_no_command = re.search(r"\s+no\s+{0}\s*$".format(command), config, re.M)
        value = False
        if has_command and not has_no_command:
            value = True
    elif arg in BOOL_PARAMS:
        value = bool(has_command)
    else:
        value = ""
        if has_command_val:
            value = has_command_val.group("value")
    return value