Repository: ansible/ansible-modules-core

Issue:
ios_facts: exception due to missing itertools
<!--- Verify first that your issue/request is not already reported in GitHub -->
##### ISSUE TYPE
- Bug Report
##### COMPONENT NAME

ios_facts
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.2.0 (devel 9963ae1d3e) last updated 2016/09/02 19:50:22 (GMT +1100)
  lib/ansible/modules/core: (detached HEAD 7e79c59d38) last updated 2016/09/02 19:50:32 (GMT +1100)
  lib/ansible/modules/extras: (detached HEAD e8a5442345) last updated 2016/09/02 19:50:32 (GMT +1100)
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

<!---
defaults
-->
##### OS / ENVIRONMENT

<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->

CentOS 7
##### SUMMARY

<!--- Explain the problem briefly -->

Running against Cisco ASR1000 resulted in exceptions being thrown.
##### STEPS TO REPRODUCE

ansible -m ios_facts -a "host=asr01.lab username=pbaker password=xxxxxx gather_subset=interfaces" localhost -vvv
##### RESULTS AND SUGGESTED FIX

Initial exception was not very helpful. 

```
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_l3i6QO/ansible_module_ios_facts.py", line 455, in <module>
    main()
  File "/tmp/ansible_l3i6QO/ansible_module_ios_facts.py", line 444, in main
    module.exit_json(out=module.from_json(runner.items))
  File "/tmp/ansible_l3i6QO/ansible_modlib.zip/ansible/module_utils/basic.py", line 1781, in from_json
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
TypeError: expected string or buffer
```

Comparing ios_facts.py to other _facts.py modules revealed the following line was missing, adding it back in seemed to help.

```
@@ -440,6 +440,7 @@ def main():
             inst.populate()
             facts.update(inst.facts)
     except Exception:
+        raise
         module.exit_json(out=module.from_json(runner.items))

     ansible_facts = dict()
```

Which led to this traceback

```
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_HvEaaO/ansible_module_ios_facts.py", line 455, in <module>
    main()
  File "/tmp/ansible_HvEaaO/ansible_module_ios_facts.py", line 440, in main
    inst.populate()
  File "/tmp/ansible_HvEaaO/ansible_module_ios_facts.py", line 238, in populate
    self.populate_ipv6_interfaces(data)
  File "/tmp/ansible_HvEaaO/ansible_module_ios_facts.py", line 272, in populate_ipv6_interfaces
    for addr, subnet in itertools.izip(addresses, subnets):
NameError: global name 'itertools' is not defined
```

So I made the following modification

```
@@ -128,7 +128,7 @@ import re
 from ansible.module_utils.basic import get_exception
 from ansible.module_utils.netcli import CommandRunner, AddCommandError
 from ansible.module_utils.ios import NetworkModule
-
+import itertools

 def add_command(runner, command):
     try:
```

Note: I'm very new to ansible, github and python, so sorry if I have gone against conventions in any way!



Discussion:
<!-- @paulbaker1985: 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 --->


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
@@ -124,6 +124,7 @@
   type: dict
 """
 import re
+import itertools
 
 from ansible.module_utils.basic import get_exception
 from ansible.module_utils.netcli import CommandRunner, AddCommandError


Test patch: