Compare commits

..

2 commits

Author SHA1 Message Date
95dce43d40 replace VM if cloudinit image is replaced 2023-03-16 23:29:28 +01:00
e542ecc3a6 improve ansible waiting times 2023-03-16 23:13:37 +01:00
5 changed files with 43 additions and 26 deletions

View file

@ -1,17 +1,7 @@
#cloud-config
hostname: dns
hostname: "${name}"
manage_etc_hosts: true
ssh_pwauth: false
disable_root: false
ssh_authorized_keys:
- "${host_public_key}"
chpasswd:
list: |
root:root
expire: False
packages:
- qemu-guest-agent
- dnsmasq
- dnsutils
package_update: true
package_upgrade: true

View file

@ -15,9 +15,9 @@ domain=dmz
# IPv4 DHCP range
dhcp-range=192.168.30.100,192.168.30.200,infinite
# Predefined DHCP hosts
dhcp-host=b8:27:eb:b9:ab:e2,esrom,192.168.30.2
dhcp-host=b4:2e:99:77:1b:da,max,192.168.30.3
dhcp-host=d8:5e:d3:47:33:6e,lewis,192.168.30.6
dhcp-host=b8:27:eb:b9:ab:e2,esrom
dhcp-host=b4:2e:99:77:1b:da,max
dhcp-host=d8:5e:d3:47:33:6e,lewis
# Advertise router
dhcp-option=3,192.168.30.1
# Always send the IPv6 DNS server address (this machine)
@ -36,4 +36,4 @@ server=/pim.kunis.nl/192.168.30.3
log-dhcp
log-queries
# Resolve dns.dmz to addresses on main NIC
interface-name=dns.dmz,ens3
interface-name=hermes.dmz,ens3

View file

@ -2,9 +2,21 @@
- hosts: all
gather_facts: no
tasks:
- name: Wait for cloud init to finish
pause:
seconds: 120
- name: Wait for host to come up
wait_for:
state: started
port: 22
host: "{{ internal_ip }}"
delay: 10
timeout: 300
connect_timeout: 300
search_regex: OpenSSH
delegate_to: localhost
- name: Wait for cloud-init to finish
command:
cmd: cloud-init status --wait
- name: Gather facts
setup:
- name: Update repositories
apt:
autoremove: true
@ -12,6 +24,12 @@
state: latest
update_cache: yes
cache_valid_time: 86400 # One day
- name: Install packages
apt:
pkg:
- qemu-guest-agent
- dnsmasq
- dnsutils
- name: Disable systemd-resolved
systemd:
name: systemd-resolved

21
main.tf
View file

@ -33,7 +33,7 @@ resource "libvirt_cloudinit_disk" "cloudinit" {
}
resource "libvirt_domain" "ubuntu" {
name = var.name
name = "hermes"
memory = 1024
vcpu = 4
@ -42,15 +42,24 @@ resource "libvirt_domain" "ubuntu" {
}
network_interface {
network_name = "dmzbr"
hostname = "dns"
addresses = ["${var.internal_ip}/24"]
mac = "ca:fe:c0:ff:ee:07"
bridge = "dmzbr"
hostname = var.name
mac = "CA:FE:C0:FF:EE:07"
}
cloudinit = libvirt_cloudinit_disk.cloudinit.id
provisioner "local-exec" {
command = "ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -T 60 -u root -i inventory ansible.yml"
command = "ansible-playbook -e internal_ip=${var.internal_ip} -T 60 -u root -i inventory hermes.yml"
environment = {
ANSIBLE_HOST_KEY_CHECKING = "False"
}
}
lifecycle {
replace_triggered_by = [
libvirt_cloudinit_disk.cloudinit.id
]
}
}

View file

@ -1,5 +1,5 @@
variable "name" {
default = "dmzdns"
default = "hermes"
}
variable "libvirt_endpoint" {