From fca829329c11dfdff8f30f8b93a7624b6f299651 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 25 Nov 2024 23:03:32 -0500 Subject: [PATCH] Add dhall experiments --- dhall/Host.dhall | 17 +++++++++++++++++ dhall/Network.dhall | 6 ++++++ dhall/Proxmox.dhall | 17 +++++++++++++++++ dhall/Server.dhall | 18 ++++++++++++++++++ dhall/inventory.dhall | 36 ++++++++++++++++++++++++++++++++++++ dhall/ip.dhall | 11 +++++++++++ dhall/servers.dhall | 22 ++++++++++++++++++++++ dhall/services.dhall | 31 +++++++++++++++++++++++++++++++ 8 files changed, 158 insertions(+) create mode 100644 dhall/Host.dhall create mode 100644 dhall/Network.dhall create mode 100644 dhall/Proxmox.dhall create mode 100644 dhall/Server.dhall create mode 100644 dhall/inventory.dhall create mode 100644 dhall/ip.dhall create mode 100644 dhall/servers.dhall create mode 100644 dhall/services.dhall diff --git a/dhall/Host.dhall b/dhall/Host.dhall new file mode 100644 index 0000000..8480241 --- /dev/null +++ b/dhall/Host.dhall @@ -0,0 +1,17 @@ +let ip = ./ip.dhall + +let Address = < ip : ip.Address | dhcp > + +let local = + \(suffix : Natural) -> + Address.ip (ip.address "192.168.1.${Natural/show suffix}" 24) + +let Host + : Type + = { name : Text, address : Address } + +let host + : Text -> Address -> Host + = \(name : Text) -> \(address : Address) -> { name, address } + +in {Host, Address, host, local} diff --git a/dhall/Network.dhall b/dhall/Network.dhall new file mode 100644 index 0000000..6ff7f5b --- /dev/null +++ b/dhall/Network.dhall @@ -0,0 +1,6 @@ +let IP = + { Type = { address : Text, prefixLength : Natural } + , default.prefixLength = 24 + } + +in { Network } diff --git a/dhall/Proxmox.dhall b/dhall/Proxmox.dhall new file mode 100644 index 0000000..98cc0e2 --- /dev/null +++ b/dhall/Proxmox.dhall @@ -0,0 +1,17 @@ +let ProxmoxServerConfig = { id : Natural, address : Text } + +let Proxmox = < LXC : ProxmoxServerConfig | VM : ProxmoxServerConfig > + +let lxc = \(id : Natural) -> \(address : Text) -> Proxmox.LXC { id, address } + +let vm = \(id : Natural) -> \(address : Text) -> Proxmox.VM { id, address } + +let ipAddress = + \(server : Proxmox) -> + merge + { LXC = \(config : ProxmoxServerConfig) -> config.address + , VM = \(config : ProxmoxServerConfig) -> config.address + } + server + +in { LXC = Proxmox.LXC, VM = Proxmox.VM, lxc, ipAddress } diff --git a/dhall/Server.dhall b/dhall/Server.dhall new file mode 100644 index 0000000..2451d94 --- /dev/null +++ b/dhall/Server.dhall @@ -0,0 +1,18 @@ +let Simple = + { Type = { address : Text, hostnames : List Text } + , default.hostnames = [] : List Text + } + +let Proxmox = ./Proxmox.dhall + +let Server = < Simple : Simple | Proxmox : Proxmox > + +let ipAddress = + \(server : Server) -> + merge + { Simple = \(s : Simple) -> s.address + , Proxmox = \(s : Proxmox.Proxmox) -> Proxmox.ipAddress s + } + server + +in { ipAddress } diff --git a/dhall/inventory.dhall b/dhall/inventory.dhall new file mode 100644 index 0000000..f98384f --- /dev/null +++ b/dhall/inventory.dhall @@ -0,0 +1,36 @@ +let ip = ./ip.dhall + +let Host = ./Host.dhall + +let servers = ./servers.dhall + +let render = + \(host : Host.Host) -> + let domain = "sailmaker.fenix.lgbt" + + let renderAddress = + \(address : Host.Address) -> + merge + { ip = \(ip : ip.Address) -> ip.address + , dhcp = "${host.name}.${domain}" + } + address + + in { ansible_host = renderAddress host.address } + +in { servers.hosts + = + { reason = render servers.reason, nomadix = render servers.nomadix } + , appliances.hosts.ipowerswitch = render servers.ipowerswitch + , virtual.hosts + = + { pihole = render servers.pihole + , wireguard = render servers.wireguard + , lldap = render servers.lldap + , traefik = render servers.traefik + , homeassistant = render servers.homeassistant + , mqtt = render servers.mqtt + , heimdall = render servers.heimdall + } + , sailmaker.children = { servers = {}, appliances = {}, virtual = {} } + } diff --git a/dhall/ip.dhall b/dhall/ip.dhall new file mode 100644 index 0000000..d182b8e --- /dev/null +++ b/dhall/ip.dhall @@ -0,0 +1,11 @@ +let Address + : Type + = { address : Text, prefixLength : Natural } + +let address + : Text -> Natural -> Address + = \(address : Text) -> + \(prefixLength : Natural) -> + { address, prefixLength } + +in { Address, address } diff --git a/dhall/servers.dhall b/dhall/servers.dhall new file mode 100644 index 0000000..e4c1d72 --- /dev/null +++ b/dhall/servers.dhall @@ -0,0 +1,22 @@ +let Proxmox = ./Proxmox.dhall + +let Host = ./Host.dhall + +let dhcp = Host.Address.dhcp + +let host = Host.host + +let local = Host.local + +in { router = host "reason" (local 1) + , pihole = host "pihole" (local 2) + , nomadix = host "nomadix" (local 5) + , wireguard = host "wireguard" (local 6) + , lldap = host "lldap" (local 7) + , traefik = host "traefik" (local 8) + , homeassistant = host "home-assistant" (local 13) + , mqtt = host "mqtt" (local 14) + , ipowerswitch = host "ipowerswitch" (local 99) + , reason = host "reason" (local 183) + , heimdall = host "heimdall-dashboard" dhcp + } diff --git a/dhall/services.dhall b/dhall/services.dhall new file mode 100644 index 0000000..fc99817 --- /dev/null +++ b/dhall/services.dhall @@ -0,0 +1,31 @@ +let ProxmoxServer = { id : Natural } + +let Protocol = < HTTP | HTTPS > + +let Backend = + { Type = { protocol : Protocol, host : Text, port : Natural } + , default = { protocol = Protocol.HTTP, port = 80 } + } + +let Service = + { Type = + { name : Text + , hostname : Optional Text + , backends : List Backend.Type + } + , default = { hostname = None Text, backends = [] : List Backend.Type } + } + +let domain = "sailmaker.fenix.lgbt" + +let hostname + : Text -> Text + = \(name : Text) -> "${name}.${domain}" + +let services + : List Service.Type + = [ Service::{ name = "pihole", hostname = Some (hostname "pi-hole") } + , Service::{ name = "heimdall" } + ] + +in services