WIP: Initial VM provisioning #4

Closed
cyclane wants to merge 38 commits from initial-vm-provisioning into main
1 changed files with 38 additions and 23 deletions
Showing only changes of commit 763958634e - Show all commits

View File

@ -31,30 +31,21 @@
api_token_secret: "{{ api_token_secret }}" api_token_secret: "{{ api_token_secret }}"
name: "{{ vmname }}" name: "{{ vmname }}"
tasks: tasks:
# Initial setup
- name: Create VM - name: Create VM
community.general.proxmox_kvm: community.general.proxmox_kvm:
clone: "{{ node }}-debian-12" clone: "{{ node }}-debian-12"
storage: nvme storage: nvme
register: create register: create
- name: Initial boot - name: Wait for status
when: create.changed is true community.general.proxmox_kvm:
block: state: current
- name: Start register: vm
community.general.proxmox_kvm: retries: 30
state: started delay: 10
register: start until: vm.status is defined
retries: 30
delay: 10 # Networking
until: start.status is defined
- name: Wait
ansible.builtin.wait_for:
timeout: 180
- name: Poweroff
community.general.proxmox_kvm:
state: stopped
- name: Debug
ansible.builtin.debug:
var: create
- name: Add HOME NIC - name: Add HOME NIC
community.general.proxmox_nic: community.general.proxmox_nic:
interface: net0 interface: net0
@ -65,6 +56,27 @@
interface: net1 interface: net1
firewall: false firewall: false
bridge: SRV bridge: SRV
# Initial boot
# For some reason debian cloud images don't use
# cloud-init for networking on first boot (cloud-init files
# are regenerated AFTER networking starts). But we need the
# hostname to be registered with DHCP later on so ¯\_(ツ)_/¯
- name: Initial boot
when: create.changed is true
block:
- name: Start
community.general.proxmox_kvm:
state: started
register: start
- name: Wait # Initial apt update, apt upgrade, cloud-init
ansible.builtin.wait_for:
timeout: 180
- name: Poweroff
community.general.proxmox_kvm:
state: stopped
# VM Configuration
- name: Resize disk - name: Resize disk
community.general.proxmox_disk: community.general.proxmox_disk:
disk: scsi0 disk: scsi0
@ -85,16 +97,19 @@
onboot: true onboot: true
cores: 2 cores: 2
memory: 2048 memory: 2048
# We have now enabled qemu guest agent, but have not installed it
# Rebooting will timeout if started
- name: Retart VM # doesn't start if stopped - name: Retart VM # doesn't start if stopped
when: when:
- create.status is defined - vm.status is defined
- create.status == "running" - vm.status == "running"
community.general.proxmox_kvm: community.general.proxmox_kvm:
state: restarted state: restarted
timeout: 60 timeout: 60
- name: Start VM # start if stopped - name: Start VM # start if stopped
when: when:
- create.status is defined - vm.status is defined
- create.status != "running" - vm.status != "running"
community.general.proxmox_kvm: community.general.proxmox_kvm:
state: started state: started