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

    data = get_config(module, flags=["| section 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 [ios_logging : Set up host logging] *************************************************************************************************************************************************************************************************************************************
task path: /Users/dnewswan/code/ansible/test/integration/targets/ios_logging/tests/cli/basic.yaml:2
<ios01> using connection plugin network_cli
<ios01> socket_path: /Users/dnewswan/.ansible/pc/e9c21a7b4c
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/ios.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/ios/ios_logging.py
<ios01> ESTABLISH LOCAL CONNECTION FOR USER: dnewswan
<ios01> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<ios01> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468 `" &amp;&amp; echo ansible-tmp-1500560665.01-100918175809468="` echo /Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468 `" ) &amp;&amp; sleep 0'
<ios01> PUT /var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/tmpegPiUR TO /Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468/ios_logging.py
<ios01> EXEC /bin/sh -c 'chmod u+x /Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468/ /Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468/ios_logging.py &amp;&amp; sleep 0'
<ios01> EXEC /bin/sh -c 'python /Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468/ios_logging.py; rm -rf "/Users/dnewswan/.ansible/tmp/ansible-tmp-1500560665.01-100918175809468/" > /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_BoAGy3/ansible_module_ios_logging.py", line 355, in <module>
main()
File "/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_BoAGy3/ansible_module_ios_logging.py", line 342, in main
have = map_config_to_obj(module)
File "/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_BoAGy3/ansible_module_ios_logging.py", line 236, in map_config_to_obj
if match.group(1) in dest_group:
AttributeError: 'NoneType' object has no attribute 'group'

fatal: [ios01]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_BoAGy3/ansible_module_ios_logging.py\", line 355, in <module>\n    main()\n  File \"/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_BoAGy3/ansible_module_ios_logging.py\", line 342, in main\n    have = map_config_to_obj(module)\n  File \"/var/folders/ql/d9_087wj4cd10grvwzxmk4hc0000gn/T/ansible_BoAGy3/ansible_module_ios_logging.py\", line 236, 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", "host", "monitor", "buffered", "on")

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

    for line in data.split("\n"):
        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