move to new module setup (#2)

Reviewed-on: https://git.pim.kunis.nl/home/hermes/pulls/2
This commit is contained in:
Pim Kunis 2023-04-10 11:21:58 +00:00
parent d13fb8ee95
commit 1088fefdb2
20 changed files with 9 additions and 64 deletions

View file

@ -1,8 +0,0 @@
[defaults]
roles_path=roles
inventory=inventory
interpreter_python=/usr/bin/python3
vault_password_file=util/secret-service-client.sh
[diff]
always = True

View file

@ -1 +0,0 @@
internal_ip: 192.168.30.7

View file

@ -1,6 +0,0 @@
all:
hosts:
hermes:
ansible_connection: ssh
ansible_user: root
ansible_host: 192.168.30.7

View file

@ -7,7 +7,7 @@
wait_for:
state: started
port: 22
host: "{{ internal_ip }}"
host: "192.168.30.7"
timeout: 300
connect_timeout: 300
search_regex: OpenSSH

56
main.tf
View file

@ -1,7 +1,7 @@
terraform {
backend "pg" {
schema_name = "dmz_dns"
conn_str = "postgres://terraform@10.42.0.1/terraform_state"
conn_str = "postgres://terraform@10.42.0.1/terraform_state"
}
required_providers {
@ -18,51 +18,11 @@ provider "libvirt" {
uri = "qemu+ssh://root@atlas.lan/system"
}
resource "libvirt_volume" "main_disk" {
name = "${var.name}.iso"
pool = "disk"
size = 1024 * 1024 * 1024 * 15
base_volume_name = "debian-bookworm.qcow2"
base_volume_pool = "iso"
}
resource "libvirt_cloudinit_disk" "cloudinit" {
name = "${var.name}.iso"
pool = "init"
user_data = templatefile("cloud_init.cfg.tftpl", { name = var.name, admin_authorized_keys = var.admin_authorized_keys })
network_config = templatefile("network_config.cfg.tftpl", { internal_ip = var.internal_ip })
}
resource "libvirt_domain" "ubuntu" {
name = var.name
memory = 1024
vcpu = 4
autostart = true
disk {
volume_id = libvirt_volume.main_disk.id
}
network_interface {
bridge = "dmzbr"
hostname = var.name
mac = "CA:FE:C0:FF:EE:07"
}
cloudinit = libvirt_cloudinit_disk.cloudinit.id
provisioner "local-exec" {
command = "ansible-playbook -e internal_ip=${var.internal_ip} -T 60 -u root -i ${var.ansible_inventory} ${var.ansible_playbook}"
environment = {
ANSIBLE_HOST_KEY_CHECKING = "False"
ANSIBLE_CONFIG = "${var.ansible_cfg}"
}
}
lifecycle {
replace_triggered_by = [
libvirt_cloudinit_disk.cloudinit.id
]
}
module "vm" {
source = "git::https://git.pim.kunis.nl/home/tf-modules.git//debian"
name = "hermes"
use_host_cert = false
fixed_address = "192.168.30.7/24"
ansible_command = "ANSIBLE_ROLES_PATH=roles ANSIBLE_HOST_KEY_CHECKING=False ANSIBLE_VAULT_PASSWORD_FILE=util/secret-service-client.sh ansible-playbook -u root -i '192.168.30.7,' hermes.yml"
mac = "CA:FE:C0:FF:EE:07"
}