# Buggy code
def map_config_to_obj(module):
    obj = []
    dest_group = ("console", "hostnameprefix", "monitor", "buffered", "on")

    data = get_config(module, flags=["logging"])

    for line in data.split("\n"):
        match = re.search(r"logging (\S+)", line, re.M)

        if match.group(1) in dest_group:
            dest = match.group(1)
        else:
            pass

        obj.append(
            {
                "dest": dest,
                "name": parse_name(line, dest),
                "size": parse_size(line, dest),
                "facility": parse_facility(line),
                "level": parse_level(line, dest),
            }
        )

    return obj


# Traceback (AttributeError)
TASK [iosxr_logging : Set up host logging] ***********************************************************************************************************************************************************************************************************************************
task path: /Users/dnewswan/code/ansible/test/integration/targets/iosxr_logging/tests/cli/basic.yaml:2
<iosxr01> using connection plugin network_cli
<iosxr01> socket_path: /Users/dnewswan/.ansible/pc/c519def7ce
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/basic.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/iosxr.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/_text.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/parsing/__init__.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/pycompat24.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/six/__init__.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/six/_six.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/connection.py
Using module_utils file /Users/dnewswan/code/ansible/lib/ansible/module_utils/network_common.py
Using module file /Users/dnewswan/code/ansible/lib/ansible/modules/network/iosxr/iosxr_logging.py
<iosxr01> ESTABLISH LOCAL CONNECTION FOR USER: dnewswan
<iosxr01> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<iosxr01> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006 `" &amp;&amp; echo ansible-tmp-1500565779.7-23570874379006="` echo /Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006 `" ) &amp;&amp; sleep 0'
<iosxr01> PUT /var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/tmpRiQQSF TO /Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006/iosxr_logging.py
<iosxr01> EXEC /bin/sh -c 'chmod u+x /Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006/ /Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006/iosxr_logging.py &amp;&amp; sleep 0'
<iosxr01> EXEC /bin/sh -c 'python /Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006/iosxr_logging.py; rm -rf "/Users/dnewswan/.ansible/tmp/ansible-tmp-1500565779.7-23570874379006/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_GQ9W8l/ansible_module_iosxr_logging.py", line 358, in <module>
main()
File "/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_GQ9W8l/ansible_module_iosxr_logging.py", line 344, in main
have = map_config_to_obj(module)
File "/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_GQ9W8l/ansible_module_iosxr_logging.py", line 240, in map_config_to_obj
if match.group(1) in dest_group:
AttributeError: 'NoneType' object has no attribute 'group'

fatal: [iosxr01]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_GQ9W8l/ansible_module_iosxr_logging.py\", line 358, in <module>\n    main()\n  File \"/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_GQ9W8l/ansible_module_iosxr_logging.py\", line 344, in main\n    have = map_config_to_obj(module)\n  File \"/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_GQ9W8l/ansible_module_iosxr_logging.py\", line 240, in map_config_to_obj\n    if match.group(1) in dest_group:\nAttributeError: 'NoneType' object has no attribute 'group'\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

# Fixed code
def map_config_to_obj(module):
    obj = []
    dest_group = ("console", "hostnameprefix", "monitor", "buffered", "on")

    data = get_config(module, flags=["logging"])
    lines = data.split("\n")

    for line in lines:
        match = re.search(r"logging (\S+)", line, re.M)
        if match:
            if match.group(1) in dest_group:
                dest = match.group(1)
                obj.append(
                    {
                        "dest": dest,
                        "name": parse_name(line, dest),
                        "size": parse_size(line, dest),
                        "facility": parse_facility(line),
                        "level": parse_level(line, dest),
                    }
                )

    return obj