# Buggy code
def populate_filesystems(self):
    data = self.responses[0]
    fs = re.findall(r"^Directory of (.+)/", data, re.M)
    return dict(filesystems=fs)


# Traceback (TypeError)
TASK [eos_facts] **********************************************************************************************************************
task path: /Users/lynchg/git/arista/veos/single_switch/tst.yml:23
<192.168.56.201> connection transport is eapi
Using module file /Users/lynchg/git/github.com/ansible/ansible/lib/ansible/modules/network/eos/eos_facts.py
<192.168.56.201> ESTABLISH LOCAL CONNECTION FOR USER: lynchg
<192.168.56.201> EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
<192.168.56.201> EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831 `" &amp;&amp; echo ansible-tmp-1491224118.54-180014088550831="` echo /Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831 `" ) &amp;&amp; sleep 0'
<192.168.56.201> PUT /var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/tmp7j07b9 TO /Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831/eos_facts.py
<192.168.56.201> EXEC /bin/sh -c 'chmod u+x /Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831/ /Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831/eos_facts.py &amp;&amp; sleep 0'
<192.168.56.201> EXEC /bin/sh -c '/usr/bin/python /Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831/eos_facts.py; rm -rf "/Users/lynchg/.ansible/tmp/ansible-tmp-1491224118.54-180014088550831/" > /dev/null 2>&amp;1 &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
File "/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py", line 378, in <module>
main()
File "/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py", line 366, in main
inst.populate()
File "/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py", line 199, in populate
self.facts.update(self.populate_filesystems())
File "/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py", line 205, in populate_filesystems
fs = re.findall(r'^Directory of (.+)/', data, re.M)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 181, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer

fatal: [switch-1]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "Traceback (most recent call last):\n  File \"/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py\", line 378, in <module>\n    main()\n  File \"/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py\", line 366, in main\n    inst.populate()\n  File \"/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py\", line 199, in populate\n    self.facts.update(self.populate_filesystems())\n  File \"/var/folders/y9/tdhfsb6n3nvg1frs229pq4cds79p1v/T/ansible_tUAZjP/ansible_module_eos_facts.py\", line 205, in populate_filesystems\n    fs = re.findall(r'^Directory of (.+)/', data, re.M)\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py\", line 181, in findall\n    return _compile(pattern, flags).findall(string)\nTypeError: expected string or buffer\n",
"module_stdout": "",
"msg": "MODULE FAILURE",
"rc": 0
}

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

# Fixed code
def populate_filesystems(self):
    data = self.responses[0]

    if isinstance(data, dict):
        data = data["messages"][0]

    fs = re.findall(r"^Directory of (.+)/", data, re.M)
    return dict(filesystems=fs)