summaryrefslogtreecommitdiff
path: root/create.py
diff options
context:
space:
mode:
Diffstat (limited to 'create.py')
-rwxr-xr-xcreate.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/create.py b/create.py
index a9d81a5..c3fc5dd 100755
--- a/create.py
+++ b/create.py
@@ -6,6 +6,7 @@ import subprocess
import requests
import getpass
import textwrap
+import yaml
from dataclasses import dataclass
from typing import Dict, Optional
from abc import ABC, abstractmethod
@@ -28,8 +29,7 @@ class Config:
GROUP_VARS = Path("group_vars/")
NGINX_SITES_ENABLED = ANSIBLE_ROLES / Path("outbound/templates/proxy/nginx/conf.d")
- LABDNS_GROUP_VARS = GROUP_VARS / Path("labdns.yml")
- LABDNS_DELIMITER = "internal_services:" + "\n"
+ MESH_GROUP_VARS = GROUP_VARS / Path("all.yml")
EXTERNAL_LOADBALANCER_HOST = "outbound.liz.coffee"
LOADBALANCER_INVENTORY_LINE = textwrap.dedent(
"""\
@@ -81,22 +81,24 @@ class CloudflareDns:
@dataclass
class HomelabDns:
group_vars: Path
- delimiter: str
+ start_delimiter: str
+ end_delimiter: str
def put_internal(self, dns_prefix: str) -> bool:
new_lines = []
with self.group_vars.open("r") as f:
lines = f.readlines()
try:
- internal_services = lines.index(self.delimiter)
+ mesh_start = lines.index(self.start_delimiter)
+ mesh_end = lines.index(self.end_delimiter)
except ValueError:
- logger.error(f"Cannot find delimiter {self.delimiter} in {self.group_vars}")
+ logger.error(f"Cannot find delimiters")
return False
- new_lines = (
- lines[0:internal_services + 1]
- + [f" - {dns_prefix}.{{{{ domain }}}}\n"]
- + lines[internal_services + 1:]
- )
+ mesh = yaml.safe_load("\n".join(lines[mesh_start:mesh_end]))
+ mesh['liz']['private_records'] += [{"type": "A", "name": dns_prefix + ".{{ domain }}", "ip": "{{ loadbalancer_ip }}"}]
+ new_mesh = yaml.dump(mesh)
+ new_lines = lines[0:mesh_start] + [self.start_delimiter, yaml.dump(mesh)] + [mesh_end:]
+
if not new_lines:
return False
with self.group_vars.open("w") as f:
@@ -291,7 +293,9 @@ def main():
if args.internal:
logger.info("Configuring internal DNS via LabDNS...")
dns = HomelabDns(
- group_vars=Config.LABDNS_GROUP_VARS, delimiter=Config.LABDNS_DELIMITER
+ group_vars=Config.MESH_GROUP_VARS
+ start_delimiter="# -- <mesh> --\n",
+ end_delimiter="# -- </mesh> --\n"
)
success = dns.put_internal(args.service_name)
if not success: