Parser: add template support

This commit is contained in:
Akemi Izuko 2024-05-26 18:33:08 -06:00
parent 847b2c9596
commit fab1f94faa
Signed by: akemi
GPG key ID: 8DE0764E1809E9FC

View file

@ -66,9 +66,12 @@ def expand_for_loop(props):
return expand
def get_ssh_props(data):
def get_ssh_props(data, hosts):
props = list()
if data.get('template'):
props = list(hosts[data.get('template')])
for k, v in data["ssh_props"].items():
if isinstance(v, list):
for x in v:
@ -79,6 +82,16 @@ def get_ssh_props(data):
return props
def remove_templates(expanded, data):
hosts = dict(expanded)
for host, props in data.items():
if host.startswith('__'):
del hosts[host]
return hosts
def stringify_booleans(props):
pattern = re.compile(r"(True|False)$")
@ -101,7 +114,7 @@ def parse_yaml(data):
for host, props in data.items():
parsed = list()
parsed.extend(get_ssh_props(props))
parsed.extend(get_ssh_props(props, expanded))
parsed.extend(expand_for_loop(props))
parsed = stringify_booleans(parsed)
@ -109,6 +122,7 @@ def parse_yaml(data):
expanded[host] = sorted(parsed)
expanded = remove_templates(expanded, data)
return expanded