1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

If ec2 fact has ':' or '-', change to '_'

Change ec2 fact names with colons (:) or dashes (:) to undescore (_)
so that they can be used in templates.

Note that this makes copies instead of replacing the exisitng fact
names to avoid breaking existing playbooks.
This commit is contained in:
Lorin Hochstein 2013-01-31 21:00:25 -05:00
parent f7e286cf34
commit 4d38c68489

View file

@ -96,12 +96,21 @@ class Ec2Metadata(object):
else: else:
self._data['%s' % (new_uri)] = content self._data['%s' % (new_uri)] = content
def fix_invalid_varnames(self, data):
"""Change ':'' and '-' to '_' to ensure valid template variable names"""
for (key, value) in data.items():
if ':' in key or '-' in key:
newkey = key.replace(':','_').replace('-','_')
data[newkey] = value
def run(self): def run(self):
self.fetch(self.uri_meta) # populate _data self.fetch(self.uri_meta) # populate _data
data = self._mangle_fields(self._data, data = self._mangle_fields(self._data,
self.uri_meta) self.uri_meta)
data[self._prefix % 'user-data'] = self._fetch(self.uri_user) data[self._prefix % 'user-data'] = self._fetch(self.uri_user)
data[self._prefix % 'public-key'] = self._fetch(self.uri_ssh) data[self._prefix % 'public-key'] = self._fetch(self.uri_ssh)
self.fix_invalid_varnames(data)
return data return data