* make ec2_facts python3 compatible * remove parentheses and use pop() instead of del
This commit is contained in:
parent
a108f0fcd3
commit
380ac577c6
1 changed files with 5 additions and 6 deletions
|
@ -57,7 +57,7 @@ EXAMPLES = '''
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
socket.setdefaulttimeout(5)
|
socket.setdefaulttimeout(5)
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ class Ec2Metadata(object):
|
||||||
data = response.read()
|
data = response.read()
|
||||||
else:
|
else:
|
||||||
data = None
|
data = None
|
||||||
return data
|
return to_text(data)
|
||||||
|
|
||||||
def _mangle_fields(self, fields, uri, filter_patterns=['public-keys-0']):
|
def _mangle_fields(self, fields, uri, filter_patterns=['public-keys-0']):
|
||||||
new_fields = {}
|
new_fields = {}
|
||||||
|
@ -110,7 +110,7 @@ class Ec2Metadata(object):
|
||||||
new_key = "".join(split_fields)
|
new_key = "".join(split_fields)
|
||||||
new_fields[self._prefix % new_key] = value
|
new_fields[self._prefix % new_key] = value
|
||||||
for pattern in filter_patterns:
|
for pattern in filter_patterns:
|
||||||
for key in new_fields.keys():
|
for key in dict(new_fields):
|
||||||
match = re.search(pattern, key)
|
match = re.search(pattern, key)
|
||||||
if match:
|
if match:
|
||||||
new_fields.pop(key)
|
new_fields.pop(key)
|
||||||
|
@ -138,11 +138,10 @@ class Ec2Metadata(object):
|
||||||
|
|
||||||
def fix_invalid_varnames(self, data):
|
def fix_invalid_varnames(self, data):
|
||||||
"""Change ':'' and '-' to '_' to ensure valid template variable names"""
|
"""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:
|
if ':' in key or '-' in key:
|
||||||
newkey = key.replace(':', '_').replace('-', '_')
|
newkey = key.replace(':', '_').replace('-', '_')
|
||||||
del data[key]
|
data[newkey] = data.pop(key)
|
||||||
data[newkey] = value
|
|
||||||
|
|
||||||
def add_ec2_region(self, data):
|
def add_ec2_region(self, data):
|
||||||
"""Use the 'ansible_ec2_placement_availability_zone' key/value
|
"""Use the 'ansible_ec2_placement_availability_zone' key/value
|
||||||
|
|
Loading…
Reference in a new issue