parameterize ip

This commit is contained in:
Pim Kunis 2023-03-11 19:05:42 +01:00
parent a6afac22f5
commit 59a3fa8f91
3 changed files with 8 additions and 4 deletions

View file

@ -29,7 +29,7 @@ resource "libvirt_cloudinit_disk" "cloudinit" {
name = "${var.name}.iso" name = "${var.name}.iso"
pool = "init" pool = "init"
user_data = templatefile("cloud_init.cfg.tftpl", { name = var.name, host_public_key = var.host_public_key }) user_data = templatefile("cloud_init.cfg.tftpl", { name = var.name, host_public_key = var.host_public_key })
network_config = templatefile("network_config.cfg.tftpl", {}) network_config = templatefile("network_config.cfg.tftpl", { internal_ip = var.internal_ip})
} }
resource "libvirt_domain" "ubuntu" { resource "libvirt_domain" "ubuntu" {
@ -44,13 +44,13 @@ resource "libvirt_domain" "ubuntu" {
network_interface { network_interface {
network_name = "dmzbr" network_name = "dmzbr"
hostname = var.name hostname = var.name
addresses = ["192.168.30.7/24"] addresses = ["${var.internal_ip}/24"]
mac = "ca:fe:c0:ff:ee:07" mac = "ca:fe:c0:ff:ee:07"
} }
cloudinit = libvirt_cloudinit_disk.cloudinit.id cloudinit = libvirt_cloudinit_disk.cloudinit.id
provisioner "local-exec" { provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -T 60 -u root -i '192.168.30.7,' ansible.yml" command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -T 60 -u root -i '${var.internal_ip}' ansible.yml"
} }
} }

View file

@ -3,7 +3,7 @@ ethernets:
ens3: ens3:
dhcp4: false dhcp4: false
addresses: addresses:
- "192.168.30.7/24" - "${internal_ip}/24"
routes: routes:
- to: 0.0.0.0/0 - to: 0.0.0.0/0
via: 192.168.30.1 via: 192.168.30.1

View file

@ -11,3 +11,7 @@ variable "host_public_key" {
type = string type = string
default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOodpLr+FDRyKyHjucHizNLVFHZ5AQmE9GmxMnOsSoaw pimkunis@thinkpadpim" default = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOodpLr+FDRyKyHjucHizNLVFHZ5AQmE9GmxMnOsSoaw pimkunis@thinkpadpim"
} }
variable "internal_ip" {
default = "192.168.30.7"
}