# Buggy code
def populate(self):
    super(Config, self).populate()

    self.facts["config"] = self.responses

    commits = self.responses[1]
    entries = list()
    entry = None

    for line in commits.split("\n"):
        match = re.match(r"(\d+)\s+(.+)by(.+)via(.+)", line)
        if match:
            if entry:
                entries.append(entry)

            entry = dict(
                revision=match.group(1),
                datetime=match.group(2),
                by=str(match.group(3)).strip(),
                via=str(match.group(4)).strip(),
                comment=None,
            )
        else:
            entry["comment"] = line.strip()

    self.facts["commits"] = entries


# Traceback (TypeError)
celebdor@s21 ~/ansible_networking $ ansible-playbook -vvv -i inventory fetch-facts.yml
ansible-playbook 2.5.0rc1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/celebdor/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.14 (default, Jan  5 2018, 10:41:29) [GCC 7.2.1 20171224]
Using /etc/ansible/ansible.cfg as config file
Parsed /home/celebdor/ansible_networking/inventory inventory source with ini plugin
___________________________
< PLAYBOOK: fetch-facts.yml >
---------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

1 plays in fetch-facts.yml
__________________________________________
< PLAY [Demonstrate connecting to netdevs] >
------------------------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

META: ran handlers
______________________________
< TASK [Gather facts (edgeos)] >
------------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

task path: /home/celebdor/ansible_networking/fetch-facts.yml:6
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/edgeos/edgeos_facts.py
<erx.home.sepu.cz> ESTABLISH LOCAL CONNECTION FOR USER: celebdor
<erx.home.sepu.cz> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<erx.home.sepu.cz> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189 `" &amp;&amp; echo ansible-tmp-1520435074.83-180899695818189="` echo /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189 `" ) &amp;&amp; sleep 0'
<erx.home.sepu.cz> PUT /home/celebdor/.ansible/tmp/ansible-local-251093D4MoI/tmpKTLQLZ TO /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189/edgeos_facts.py
<erx.home.sepu.cz> EXEC /bin/sh -c 'chmod u+x /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189/ /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189/edgeos_facts.py &amp;&amp; sleep 0'
<erx.home.sepu.cz> EXEC /bin/sh -c '/usr/bin/python /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189/edgeos_facts.py &amp;&amp; sleep 0'
<erx.home.sepu.cz> EXEC /bin/sh -c 'rm -f -r /home/celebdor/.ansible/tmp/ansible-tmp-1520435074.83-180899695818189/ > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_my96l988/ansible_module_edgeos_facts.py", line 311, in <module>
main()
File "/tmp/ansible_my96l988/ansible_module_edgeos_facts.py", line 299, in main
inst.populate()
File "/tmp/ansible_my96l988/ansible_module_edgeos_facts.py", line 174, in populate
entry['comment'] = line.strip()
TypeError: 'NoneType' object does not support item assignment

fatal: [my-router.home.lan]: FAILED! => {
"changed": false,
"module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_my96l988/ansible_module_edgeos_facts.py\", line 311, in <module>\n    main()\n  File \"/tmp/ansible_my96l988/ansible_module_edgeos_facts.py\", line 299, in main\n    inst.populate()\n  File \"/tmp/ansible_my96l988/ansible_module_edgeos_facts.py\", line 174, in populate\n    entry['comment'] = line.strip()\nTypeError: 'NoneType' object does not support item assignment\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 1
}
to retry, use: --limit @/home/celebdor/ansible_networking/fetch-facts.retry
____________
< PLAY RECAP >
------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||

my-router.home.lan           : ok=0    changed=0    unreachable=0    failed=1

# Fixed code
def populate(self):
    super(Config, self).populate()

    self.facts["config"] = self.responses

    commits = self.responses[1]
    entries = list()
    entry = None

    for line in commits.split("\n"):
        match = re.match(r"(\d+)\s+(.+)by(.+)via(.+)", line)
        if match:
            if entry:
                entries.append(entry)

            entry = dict(
                revision=match.group(1),
                datetime=match.group(2),
                by=str(match.group(3)).strip(),
                via=str(match.group(4)).strip(),
                comment=None,
            )
        elif entry:
            entry["comment"] = line.strip()

    self.facts["commits"] = entries