From 380ac577c68d0eeff65567f5c3c2c73e1afbdd08 Mon Sep 17 00:00:00 2001 From: Sloane Hertel Date: Mon, 24 Apr 2017 16:09:46 -0400 Subject: [PATCH] [cloud] ec2_facts: make ec2_facts python3 compatible - fixes #23595 (#23872) * make ec2_facts python3 compatible * remove parentheses and use pop() instead of del --- lib/ansible/modules/cloud/amazon/ec2_facts.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/cloud/amazon/ec2_facts.py b/lib/ansible/modules/cloud/amazon/ec2_facts.py index bab010ff42..332eeb91ba 100644 --- a/lib/ansible/modules/cloud/amazon/ec2_facts.py +++ b/lib/ansible/modules/cloud/amazon/ec2_facts.py @@ -57,7 +57,7 @@ EXAMPLES = ''' import socket import re - +from ansible.module_utils._text import to_text socket.setdefaulttimeout(5) @@ -97,7 +97,7 @@ class Ec2Metadata(object): data = response.read() else: data = None - return data + return to_text(data) def _mangle_fields(self, fields, uri, filter_patterns=['public-keys-0']): new_fields = {} @@ -110,7 +110,7 @@ class Ec2Metadata(object): new_key = "".join(split_fields) new_fields[self._prefix % new_key] = value for pattern in filter_patterns: - for key in new_fields.keys(): + for key in dict(new_fields): match = re.search(pattern, key) if match: new_fields.pop(key) @@ -138,11 +138,10 @@ class Ec2Metadata(object): def fix_invalid_varnames(self, data): """Change ':'' and '-' to '_' to ensure valid template variable names""" - for (key, value) in data.items(): + for key in data: if ':' in key or '-' in key: newkey = key.replace(':', '_').replace('-', '_') - del data[key] - data[newkey] = value + data[newkey] = data.pop(key) def add_ec2_region(self, data): """Use the 'ansible_ec2_placement_availability_zone' key/value