diff --git a/.gitignore b/.gitignore index 7670350..69b62cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ build/ +*.swp ansible/ vms.json config/ __pycache__/ +password.txt diff --git a/main.py b/main.py index 7136a4a..5b14e3e 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,10 @@ location /.well-known/acme-challenge/ { if __name__ == "__main__": + password = None + with open("password.txt") as f: + password = f.read().strip("\n") + FILE = "./config/vms.json" with open(FILE) as f: jsonList = json.load(f) @@ -88,4 +92,9 @@ if __name__ == "__main__": f.write(template.render(hostname=vmo.hostname, ip=vmo.ip)) f.write("\n") - + # dump ansible + with open("./ansible/files/nsca_server.conf", "w") as f: + env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath="./templates")) + template = env.get_template("nsca_server.conf.j2") + f.write(template.render(vmList=set(filter(lambda x: x.ansible, vmList)), + password=password)) diff --git a/templates/nsca_server.conf.j2 b/templates/nsca_server.conf.j2 new file mode 100644 index 0000000..8e2d7e3 --- /dev/null +++ b/templates/nsca_server.conf.j2 @@ -0,0 +1,13 @@ +command_file = "/run/icinga2/cmd/icinga2.cmd" +user = "nagios" +log_level = 4 + +{% for vmo in vmList %} +authorize "{{ vmo.hostname }}" { + password = "{{ password }}" + hosts = "{{ vmo.hostname }}" + services = { + "*", + } +} +{% endfor %}