Repository: ansible/ansible-modules-core

Issue:
ios_facts: `dir all-filesystems | include Directory`not supported on all devices
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

ios_facts
##### ANSIBLE VERSION

```
ansible --version
ansible 2.2.0 (devel 9fe4308670) last updated 2016/09/06 19:17:13 (GMT +1100)
  lib/ansible/modules/core: (detached HEAD 982c4557d2) last updated 2016/09/06 19:17:23 (GMT +1100)
  lib/ansible/modules/extras: (detached HEAD 06bd2a5ce2) last updated 2016/09/06 19:17:32 (GMT +1100)
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/my_modules/']

```
##### CONFIGURATION
##### OS / ENVIRONMENT

3750
flash:c3750-advipservicesk9-mz.122-44.SE4.bin"
WS-C3750-24PS-S
##### SUMMARY

ogenstad: 

> `dir all-filesystems | include Directory` this is not a valid command on all ios devices.
> If it’s used in the ios_facts module there needs to be some checks to catch those errors.
> I haven’t tested the ios_facts module yet, but if you can just disable that check I’m guessing it would work.
> I.e. not use `gather_subset: all`

Thanks to @ben-cirrus (from networktocode Slack) for this bug report
##### STEPS TO REPRODUCE

<!---
- hosts: "{{ hosts }}"
  any_errors_fatal: true
  connection: local
  gather_facts: no
  vars:
     cli:
       host: "{{ ip_addr }}"
       username: "{{ user }}"
       password: "{{ password }}"
       transport: cli
  tasks:
  - ios_facts:
      provider: "{{ cli }}"
      gather_subset: all

[lab]
labswitch ip_addr=10.254.9.11
-->
##### EXPECTED RESULTS

No backtrace, facts returned
##### ACTUAL RESULTS

```
Using /etc/ansible/ansible.cfg as config file
PLAYBOOK: get_ios_facts.yml ****************************************************
1 plays in get_ios_facts.yml
PLAY [lab,] ********************************************************************
TASK [ios_facts] ***************************************************************
task path: /root/napalm-testing/get_ios_facts.yml:14
Using module file /root/ansible/lib/ansible/modules/core/network/ios/ios_facts.py
<labswitch> ESTABLISH LOCAL CONNECTION FOR USER: root
<labswitch> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277 `" && echo ansible-tmp-1473154099.74-15933157338277="` echo $HOME/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277 `" ) && sleep 0'
<labswitch> PUT /tmp/tmpxzHJfd TO /root/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277/ios_facts.py
<labswitch> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277/ /root/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277/ios_facts.py && sleep 0'
<labswitch> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277/ios_facts.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1473154099.74-15933157338277/" > /dev/null 2>&1 && sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_6pqI6u/ansible_module_ios_facts.py", line 455, in <module>
    main()
  File "/tmp/ansible_6pqI6u/ansible_module_ios_facts.py", line 437, in main
    runner.run()
  File "/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/netcli.py", line 163, in run
  File "/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/netcli.py", line 88, in run_commands
  File "/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/ios.py", line 66, in run_commands
  File "/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/shell.py", line 252, in execute
ansible.module_utils.network.NetworkError: matched error in response: dir all-filesystems | include Directory
                                   ^
% Invalid input detected at '^' marker.
NSW-CHQ-SW-LAB#
fatal: [labswitch]: FAILED! => {
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_name": "ios_facts"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_6pqI6u/ansible_module_ios_facts.py\", line 455, in <module>\n    main()\n  File \"/tmp/ansible_6pqI6u/ansible_module_ios_facts.py\", line 437, in main\n    runner.run()\n  File \"/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 163, in run\n  File \"/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/netcli.py\", line 88, in run_commands\n  File \"/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/ios.py\", line 66, in run_commands\n  File \"/tmp/ansible_6pqI6u/ansible_modlib.zip/ansible/module_utils/shell.py\", line 252, in execute\nansible.module_utils.network.NetworkError: matched error in response: dir all-filesystems | include Directory\r\n                                   ^\r\n% Invalid input detected at '^' marker.\r\n\r\nNSW-CHQ-SW-LAB#\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE"
}
        to retry, use: --limit @get_ios_facts.retry
PLAY RECAP *********************************************************************
labswitch                  : ok=0    changed=0    unreachable=0    failed=1   
```



Discussion:
<!-- @gundalow: Thanks for filing this bug report! -->

@privateip, @gundalow, ping. This issue is waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_bug_new --->

@privateip, @gundalow, ping. This issue is still waiting on your response.
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)

<!--- boilerplate: issue_renotify_maintainer --->


Resolving patch:
diff --git a/network/ios/ios_facts.py b/network/ios/ios_facts.py
--- a/network/ios/ios_facts.py
+++ b/network/ios/ios_facts.py
@@ -195,12 +195,12 @@ def parse_serialnum(self, data):
 class Hardware(FactsBase):
 
     def commands(self):
-        add_command(self.runner, 'dir all-filesystems | include Directory')
+        add_command(self.runner, 'dir | include Directory')
         add_command(self.runner, 'show version')
         add_command(self.runner, 'show memory statistics | include Processor')
 
     def populate(self):
-        data = self.runner.get_command('dir all-filesystems | include Directory')
+        data = self.runner.get_command('dir | include Directory')
         self.facts['filesystems'] = self.parse_filesystems(data)
 
         data = self.runner.get_command('show memory statistics | include Processor')


Test patch: