Repository: ansible/ansible

Issue:
'zip' template filter is missing under python3
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report

##### COMPONENT NAME
zip template filter

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.1.0
  config file = 
  configured module search path = Default w/o overrides
  python version = 3.6.0+ (default, Feb  4 2017, 11:11:33) [GCC 4.9.4]
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
None

##### 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.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
Ubuntu

##### SUMMARY
Ansible can't load zip filter under python3. The problem seems to be at this line: 
https://github.com/ansible/ansible/blob/21bd7bcbb09d21f2c9a33cd2d6ff906de3cd0926/lib/ansible/plugins/filter/mathstuff.py#L164
zip is a builtin function in python3 and is not located in itertools

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ansible -m debug -a "msg={{ [1,2,3]|zip(['a','b','c'])|list }}" all
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Output
```
<hostname> | SUCCESS => {
    "msg": [
        [
            1,
            "a"
        ],
        [
            2,
            "b"
        ],
        [
            3,
            "c"
        ]
    ]
}
```

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
<hostname> | FAILED! => {
    "failed": true,
    "msg": "template error while templating string: no filter named 'zip'. String: {{ [1,2,3]|zip(['a','b','c'])|list }}"
}
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/plugins/filter/mathstuff.py b/lib/ansible/plugins/filter/mathstuff.py
--- a/lib/ansible/plugins/filter/mathstuff.py
+++ b/lib/ansible/plugins/filter/mathstuff.py
@@ -26,6 +26,7 @@
 
 from ansible import errors
 from ansible.module_utils import basic
+from ansible.module_utils.six.moves import zip, zip_longest
 
 
 def unique(a):
@@ -153,17 +154,10 @@ def filters(self):
             'human_readable': human_readable,
             'human_to_bytes': human_to_bytes,
 
-        }
+            # zip
+            'zip': zip,
+            'zip_longest': zip_longest,
 
-        # py2 vs py3, reverse when py3 is predominant version
-        try:
-            filters['zip'] = itertools.izip
-            filters['zip_longest'] = itertools.izip_longest
-        except AttributeError:
-            try:
-                filters['zip'] = itertools.zip
-                filters['zip_longest'] = itertools.zip_longest
-            except:
-                pass
+        }
 
         return filters


Test patch: