Restructure into one folder per private repo/host, not a flat Docker/ dump
rocky-docker-lxc/, caddy-vm/, monitoring-vm/ (was missing entirely -
Grafana+Loki+Prometheus stack, refreshed and CA mount stripped same as
everything else), and automation/{ansible,automation-vm,iac}/ for the
three repos that live on the automation VM. Hawser is genuinely
deployed on all three of caddy-vm/monitoring-vm/automation-vm so it's
duplicated in each rather than picking one canonical home.
Old Ansible/ and "Infrastrucutre as Code/" content moved under
automation/ansible/old-playbooks and automation/iac/old-content as-is
for now - contents still need refreshing against the current repos and
a per-folder README, that's the next pass.
This commit is contained in:
146 files changed
+101
-84
No files matched your search
@@ -0,0 +1,3 @@
|
||||
Coming Soon...
|
||||
|
||||
A full explanation of the files in the Terraform folder and how they are laid out in order to consume the Packer built ISO, which has been uploaded into a Proxmox template, for the construction of a VM with specific parameters.
|
||||
@@ -0,0 +1,20 @@
|
||||
# VM metadata from Terraform provisioning
|
||||
vmid: ${vmid}
|
||||
vm_name: ${name}
|
||||
target_node: ${target_node}
|
||||
template: ${template}
|
||||
cores: ${cores}
|
||||
sockets: ${sockets}
|
||||
memory: ${memory}
|
||||
bridge: ${bridge}
|
||||
macaddr: ${macaddr}
|
||||
disk_size: ${disk_size}GB
|
||||
disk_storage: ${disk_storage}
|
||||
ip: ${ip}
|
||||
vlan: ${vlan}
|
||||
vm_tags:
|
||||
%{ for tag in tags ~}
|
||||
- ${tag}
|
||||
%{ endfor ~}
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
locals {
|
||||
ansible_repo_path = var.ansible_repo_path != "" ? var.ansible_repo_path : "${path.module}/../ansible"
|
||||
}
|
||||
|
||||
resource "proxmox_vm_qemu" "vm" {
|
||||
for_each = var.vms
|
||||
agent = 1
|
||||
skip_ipv6 = true
|
||||
vmid = each.value.vmid
|
||||
name = each.value.name
|
||||
target_node = each.value.target_node
|
||||
clone = each.value.template
|
||||
onboot = each.value.onboot
|
||||
os_type = "other"
|
||||
|
||||
cpu {
|
||||
type = "host"
|
||||
numa = true
|
||||
cores = each.value.cores
|
||||
sockets = each.value.sockets
|
||||
}
|
||||
|
||||
memory = each.value.memory
|
||||
balloon = 0
|
||||
scsihw = "virtio-scsi-pci"
|
||||
bootdisk = "scsi0"
|
||||
|
||||
disk {
|
||||
slot = "scsi0"
|
||||
type = "disk"
|
||||
storage = each.value.disk_storage
|
||||
size = each.value.disk_size
|
||||
format = "qcow2"
|
||||
discard = true
|
||||
}
|
||||
|
||||
network {
|
||||
id = 0
|
||||
bridge = each.value.bridge
|
||||
model = "virtio"
|
||||
macaddr = each.value.macaddr
|
||||
tag = each.value.vlan != 0 ? each.value.vlan : null
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
usb,
|
||||
]
|
||||
}
|
||||
|
||||
serial {
|
||||
id = 0
|
||||
}
|
||||
|
||||
tags = length(each.value.tags) > 0 ? join(",", each.value.tags) : null
|
||||
}
|
||||
|
||||
resource "null_resource" "wait_for_ssh" {
|
||||
for_each = var.vms
|
||||
depends_on = [proxmox_vm_qemu.vm]
|
||||
|
||||
connection {
|
||||
type = "ssh"
|
||||
host = each.value.ip
|
||||
user = "ansible"
|
||||
private_key = file("~/.ssh/auto")
|
||||
timeout = "5m"
|
||||
}
|
||||
|
||||
provisioner "local-exec" {
|
||||
command = <<EOT
|
||||
echo "Waiting for SSH on ${each.value.ip}..."
|
||||
for i in {1..30}; do
|
||||
if ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 -i ~/.ssh/auto ansible@${each.value.ip} 'echo SSH Ready' >/dev/null 2>&1; then
|
||||
echo "✅ SSH is up!"
|
||||
exit 0
|
||||
fi
|
||||
echo "Retry $i: SSH not ready yet..."
|
||||
sleep 10
|
||||
done
|
||||
echo "❌ SSH did not become available on ${each.value.ip} after timeout."
|
||||
exit 1
|
||||
EOT
|
||||
}
|
||||
}
|
||||
|
||||
resource "local_file" "host_tags" {
|
||||
for_each = var.vms
|
||||
|
||||
content = templatefile("${path.module}/host_tags.yml.tpl", {
|
||||
vmid = each.value.vmid
|
||||
name = each.value.name
|
||||
target_node = each.value.target_node
|
||||
template = each.value.template
|
||||
cores = each.value.cores
|
||||
sockets = each.value.sockets
|
||||
memory = each.value.memory
|
||||
bridge = each.value.bridge
|
||||
macaddr = each.value.macaddr
|
||||
disk_size = each.value.disk_size
|
||||
disk_storage = each.value.disk_storage
|
||||
ip = each.value.ip
|
||||
vlan = each.value.vlan
|
||||
tags = each.value.tags
|
||||
})
|
||||
|
||||
filename = "${local.ansible_repo_path}/host_vars/${each.value.name}/host_tags.yml"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
terraform {
|
||||
required_version = ">= 0.14"
|
||||
required_providers {
|
||||
proxmox = {
|
||||
source = "telmate/proxmox"
|
||||
version = "3.0.2-rc03"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "proxmox" {
|
||||
pm_tls_insecure = true
|
||||
pm_api_url = "https://host:port/api2/json"
|
||||
pm_api_token_secret = "pm_api_token_secret"
|
||||
pm_api_token_id = "pm_api_token_id"
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
vms = {
|
||||
haproxy = {
|
||||
vmid = id number here
|
||||
name = "vm name"
|
||||
target_node = "hypervisor node name"
|
||||
template = "template-name"
|
||||
onboot = true
|
||||
cores = 2
|
||||
sockets = 1
|
||||
memory = 2048
|
||||
bridge = "vmbr0"
|
||||
macaddr = "xx:x:x:x:x:x"
|
||||
disk_size = 20
|
||||
disk_storage = "storage name here"
|
||||
ip = "xx.xx.xx.x"
|
||||
gateway = "x.x.x.x"
|
||||
netmask = "24"
|
||||
vlan = "0"
|
||||
startup = {
|
||||
order = 3
|
||||
up = 10
|
||||
down = 10
|
||||
}
|
||||
tags = [
|
||||
"packages",
|
||||
"hostname_network",
|
||||
"root_password",
|
||||
"disk_resize",
|
||||
"base_users",
|
||||
"firewall_ssh",
|
||||
"endlessh",
|
||||
"portainer_agent",
|
||||
"zsh_custom",
|
||||
"cis_hardening"
|
||||
]
|
||||
}
|
||||
docker = {
|
||||
vmid = id number here
|
||||
name = "vm name"
|
||||
target_node = "hypervisor node name"
|
||||
template = "template-name"
|
||||
onboot = true
|
||||
cores = 2
|
||||
sockets = 1
|
||||
memory = 8192
|
||||
bridge = "vmbr0"
|
||||
macaddr = "xx:x:x:x:x:x"
|
||||
disk_size = 20
|
||||
disk_storage = "storage name here"
|
||||
ip = "xx.xx.xx.x"
|
||||
gateway = "x.x.x.x"
|
||||
netmask = "24"
|
||||
vlan = "0"
|
||||
startup = {
|
||||
order = 3
|
||||
up = 10
|
||||
down = 20
|
||||
}
|
||||
tags = [
|
||||
"packages",
|
||||
"hostname_network",
|
||||
"root_password",
|
||||
"disk_resize",
|
||||
"base_users",
|
||||
"firewall_ssh",
|
||||
"endlessh",
|
||||
"portainer_agent",
|
||||
"zsh_custom",
|
||||
"vault_agent",
|
||||
"cis_hardening",
|
||||
"docker_gitlab_setup"
|
||||
"s_nail",
|
||||
"lynis"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
ansible_repo_path = ""
|
||||
@@ -0,0 +1,32 @@
|
||||
variable "vms" {
|
||||
description = "Map of VMs to create"
|
||||
type = map(object({
|
||||
vmid = number
|
||||
name = string
|
||||
target_node = string
|
||||
template = string
|
||||
onboot = bool
|
||||
cores = number
|
||||
sockets = number
|
||||
memory = number
|
||||
bridge = string
|
||||
macaddr = string
|
||||
disk_size = number
|
||||
disk_storage = string
|
||||
ip = string
|
||||
gateway = string
|
||||
netmask = string
|
||||
vlan = string
|
||||
startup = object({
|
||||
order = number
|
||||
up = number
|
||||
down = number
|
||||
})
|
||||
tags = list(string)
|
||||
}))
|
||||
}
|
||||
|
||||
variable "ansible_repo_path" {
|
||||
description = "Path to the ansible repo"
|
||||
type = string
|
||||
}
|
||||
Reference in new issue
Block a user