homelab-nomad/nomad_vars.py

34 lines
830 B
Python
Executable File

#! /usr/bin/env python3
import yaml
from nomad import Nomad
def write_nomad():
nomad = Nomad()
with open("./ansible_playbooks/vars/nomad_vars.yml") as f:
vars = yaml.load(f, yaml.CLoader)
for path, items in vars.items():
# ignore special path there for terraform
if path == "nomad/oidc":
continue
print("path", path, "items", items)
if items == "DELETE":
print(nomad.variable.delete_variable(path))
else:
print(
nomad.variable.create_variable(
path,
{"Path": path, "Items": {k: str(v) for k, v in items.items()}},
)
)
def main():
write_nomad()
if __name__ == "__main__":
main()