homelab-nomad/nomad_vars.py

34 lines
830 B
Python
Raw Normal View History

#! /usr/bin/env python3
import yaml
from nomad import Nomad
2023-03-24 16:57:37 +00:00
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)
2023-03-24 16:57:37 +00:00
if items == "DELETE":
print(nomad.variable.delete_variable(path))
2023-03-24 16:57:37 +00:00
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()