Repository: ansible/ansible

Issue:
ec2_vpc_nacl.py#L148 Fails in Python 3
##### ISSUE TYPE
 - Bug Report
 - Documentation Report

##### COMPONENT NAME
modules/cloud/amazon/ec2_vpc_nacl.py#L148
##### ANSIBLE VERSION
2.3.1 using python 3.6
Apologies I fixed it by going to 2.7 so --version is off

##### CONFIGURATION
It happens on module load

##### OS / ENVIRONMENT
Debian but all

##### SUMMARY
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_a48yd03u/ansible_module_ec2_vpc_nacl.py\", line 148, in <module>\n    DEFAULT_INGRESS = dict(DEFAULT_RULE_FIELDS.items() + [('Egress', False)])\nTypeError: unsupported operand type(s) for +: 'dict_items' and 'list'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}

##### STEPS TO REPRODUCE
Use module in yml or import with python3.



##### EXPECTED RESULTS
Module load

##### ACTUAL RESULTS
TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_a48yd03u/ansible_module_ec2_vpc_nacl.py\", line 148, in <module>\n    DEFAULT_INGRESS = dict(DEFAULT_RULE_FIELDS.items() + [('Egress', False)])\nTypeError: unsupported operand type(s) for +: 'dict_items' and 'list'\n", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 0}



Discussion:
cc @mmochan
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
Now that Im off work I can debug better
here is just loading the module with python3.6

```
python ~/.conda/envs/playbooks-3/lib/python3.6/site-packages/ansible/modules/cloud/amazon/ec2_vpc_nacl.py 
Traceback (most recent call last):
  File "/home/mikela/.conda/envs/playbooks-3/lib/python3.6/site-packages/ansible/modules/cloud/amazon/ec2_vpc_nacl.py", line 148, in <module>
    DEFAULT_INGRESS = dict(DEFAULT_RULE_FIELDS.items() + [('Egress', False)])
TypeError: unsupported operand type(s) for +: 'dict_items' and 'list'

So a quick fix is simply
DEFAULT_INGRESS = dict(list(DEFAULT_RULE_FIELDS.items()) + [('Egress', False)])
DEFAULT_EGRESS = dict(list(DEFAULT_RULE_FIELDS.items()) + [('Egress', True)])

Resolving patch:
diff --git a/lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py b/lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py
--- a/lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py
+++ b/lib/ansible/modules/cloud/amazon/ec2_vpc_nacl.py
@@ -145,8 +145,8 @@
     'Protocol': '-1'
 }
 
-DEFAULT_INGRESS = dict(DEFAULT_RULE_FIELDS.items() + [('Egress', False)])
-DEFAULT_EGRESS = dict(DEFAULT_RULE_FIELDS.items() + [('Egress', True)])
+DEFAULT_INGRESS = dict(list(DEFAULT_RULE_FIELDS.items()) + [('Egress', False)])
+DEFAULT_EGRESS = dict(list(DEFAULT_RULE_FIELDS.items()) + [('Egress', True)])
 
 # VPC-supported IANA protocol numbers
 # http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml


Test patch: