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:
parent
f7e286cf34
commit
4d38c68489
1 changed files with 16 additions and 7 deletions
|
@ -96,12 +96,21 @@ class Ec2Metadata(object):
|
|||
else:
|
||||
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):
|
||||
self.fetch(self.uri_meta) # populate _data
|
||||
data = self._mangle_fields(self._data,
|
||||
self.uri_meta)
|
||||
data[self._prefix % 'user-data'] = self._fetch(self.uri_user)
|
||||
data[self._prefix % 'public-key'] = self._fetch(self.uri_ssh)
|
||||
self.fix_invalid_varnames(data)
|
||||
return data
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue