2022-11-21 00:24:00 +00:00
|
|
|
#! /usr/bin/env python3
|
2023-07-11 19:45:12 +00:00
|
|
|
import sys
|
2022-11-21 00:24:00 +00:00
|
|
|
import yaml
|
2023-07-07 22:52:52 +00:00
|
|
|
from nomad import Nomad
|
2022-11-21 00:24:00 +00:00
|
|
|
|
2023-03-24 16:57:37 +00:00
|
|
|
|
2022-11-21 00:24:00 +00:00
|
|
|
def write_nomad():
|
2023-07-07 22:52:52 +00:00
|
|
|
nomad = Nomad()
|
2022-11-21 00:24:00 +00:00
|
|
|
with open("./ansible_playbooks/vars/nomad_vars.yml") as f:
|
|
|
|
vars = yaml.load(f, yaml.CLoader)
|
|
|
|
|
|
|
|
for path, items in vars.items():
|
2023-07-07 22:52:52 +00:00
|
|
|
# ignore special path there for terraform
|
|
|
|
if path == "nomad/oidc":
|
|
|
|
continue
|
|
|
|
|
2022-11-21 00:24:00 +00:00
|
|
|
print("path", path, "items", items)
|
2023-03-24 16:57:37 +00:00
|
|
|
if items == "DELETE":
|
2023-07-07 22:52:52 +00:00
|
|
|
print(nomad.variable.delete_variable(path))
|
2023-03-24 16:57:37 +00:00
|
|
|
else:
|
2023-07-07 22:52:52 +00:00
|
|
|
print(
|
|
|
|
nomad.variable.create_variable(
|
|
|
|
path,
|
|
|
|
{"Path": path, "Items": {k: str(v) for k, v in items.items()}},
|
|
|
|
)
|
|
|
|
)
|
2022-11-21 00:24:00 +00:00
|
|
|
|
|
|
|
|
2023-07-11 19:45:12 +00:00
|
|
|
def print_sample():
|
|
|
|
clean_vars = {}
|
|
|
|
with open("./ansible_playbooks/vars/nomad_vars.yml") as f:
|
|
|
|
vars = yaml.load(f, yaml.CLoader)
|
|
|
|
|
|
|
|
for path, items in vars.items():
|
|
|
|
if items == "DELETE":
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
clean_vars[path] = {k: "VALUE" for k in items}
|
|
|
|
|
|
|
|
print(yaml.dump(clean_vars))
|
|
|
|
|
|
|
|
|
2022-11-21 00:24:00 +00:00
|
|
|
def main():
|
2023-07-11 19:45:12 +00:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == "print":
|
|
|
|
print_sample()
|
|
|
|
else:
|
|
|
|
write_nomad()
|
2022-11-21 00:24:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|