Parser: add template support
This commit is contained in:
parent
847b2c9596
commit
fab1f94faa
1 changed files with 16 additions and 2 deletions
18
src/main.py
18
src/main.py
|
@ -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
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue