Disable aliases in inventory.yaml for better readibility
User complained about the anchors and aliases in inventory.yaml, which is intended for huram to read. With anchors and aliases reduced the readbility. This change is intended to fix this. Change-Id: I99333f85d7fdda213ddf2c14e5db89825b093b56
This commit is contained in:
@@ -82,3 +82,29 @@ list:
|
||||
"""
|
||||
yaml_out = yamlutil.ansible_unsafe_dump(data, default_flow_style=False)
|
||||
self.assertEqual(yaml_out, expected)
|
||||
|
||||
def test_ansible_dumper_with_aliases(self):
|
||||
foo = {'bar': 'baz'}
|
||||
data = {'foo1': foo, 'foo2': foo}
|
||||
expected = """\
|
||||
foo1: &id001
|
||||
bar: baz
|
||||
foo2: *id001
|
||||
"""
|
||||
yaml_out = yamlutil.ansible_unsafe_dump(data, default_flow_style=False)
|
||||
self.assertEqual(yaml_out, expected)
|
||||
|
||||
def test_ansible_dumper_ignore_aliases(self):
|
||||
foo = {'bar': 'baz'}
|
||||
data = {'foo1': foo, 'foo2': foo}
|
||||
expected = """\
|
||||
foo1:
|
||||
bar: baz
|
||||
foo2:
|
||||
bar: baz
|
||||
"""
|
||||
yaml_out = yamlutil.ansible_unsafe_dump(
|
||||
data,
|
||||
ignore_aliases=True,
|
||||
default_flow_style=False)
|
||||
self.assertEqual(yaml_out, expected)
|
||||
|
||||
@@ -2430,7 +2430,10 @@ class AnsibleJob(object):
|
||||
inventory['all']['vars']['zuul'] = self.zuul_vars
|
||||
with open(self.jobdir.inventory, 'w') as inventory_yaml:
|
||||
inventory_yaml.write(
|
||||
yaml.ansible_unsafe_dump(inventory, default_flow_style=False))
|
||||
yaml.ansible_unsafe_dump(
|
||||
inventory,
|
||||
ignore_aliases=True,
|
||||
default_flow_style=False))
|
||||
|
||||
def writeSetupInventory(self):
|
||||
jobdir_playbook = self.jobdir.setup_playbook
|
||||
|
||||
@@ -142,6 +142,11 @@ class AnsibleUnsafeDumper(yaml.SafeDumper):
|
||||
pass
|
||||
|
||||
|
||||
class AnsibleUnsafeDumperWithoutAliases(yaml.SafeDumper):
|
||||
def ignore_aliases(self, data):
|
||||
return True
|
||||
|
||||
|
||||
class AnsibleUnsafeLoader(yaml.SafeLoader):
|
||||
pass
|
||||
|
||||
@@ -153,7 +158,12 @@ AnsibleUnsafeLoader.add_constructor(AnsibleUnsafeStr.yaml_tag,
|
||||
|
||||
|
||||
def ansible_unsafe_dump(data, *args, **kwargs):
|
||||
return yaml.dump(data, *args, Dumper=AnsibleUnsafeDumper, **kwargs)
|
||||
ignore_aliases = kwargs.pop('ignore_aliases', False)
|
||||
if ignore_aliases:
|
||||
return yaml.dump(data, *args, Dumper=AnsibleUnsafeDumperWithoutAliases,
|
||||
**kwargs)
|
||||
else:
|
||||
return yaml.dump(data, *args, Dumper=AnsibleUnsafeDumper, **kwargs)
|
||||
|
||||
|
||||
def ansible_unsafe_load(stream, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user