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.
pull/1954/head
Lorin Hochstein 12 years ago
parent f7e286cf34
commit 4d38c68489

@ -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

Loading…
Cancel
Save