diff --git a/ansible/infra/nodito/33_proxmox_debian_cloud_template.yml b/ansible/infra/nodito/33_proxmox_debian_cloud_template.yml index 061a2a3..40cf26e 100644 --- a/ansible/infra/nodito/33_proxmox_debian_cloud_template.yml +++ b/ansible/infra/nodito/33_proxmox_debian_cloud_template.yml @@ -78,15 +78,14 @@ set_fact: ssh_keys_list: "{{ ssh_key_content.content | b64decode | split('\n') | select('match', '^ssh-') | list }}" - - name: Write cloud-init user-data snippet to install qemu-guest-agent + - name: Write cloud-init vendor-data snippet to install qemu-guest-agent copy: dest: "{{ zfs_pool_mountpoint }}/snippets/{{ qemu_agent_snippet_filename }}" mode: '0644' content: | #cloud-config - user: {{ proxmox_ciuser }} - ssh_authorized_keys: - {{ ssh_keys_list | to_nice_yaml | indent(10, first=True) }} + # Vendor-data snippet: Proxmox will automatically set hostname from VM name when using vendor-data + # User info (ciuser/sshkeys) is set separately via Terraform/Proxmox parameters package_update: true package_upgrade: true packages: @@ -164,7 +163,7 @@ ] + (proxmox_ci_upgrade | bool | ternary(['--ciupgrade 1'], [])) - + ['--cicustom user=local:snippets/' ~ qemu_agent_snippet_filename] + + ['--cicustom vendor=local:snippets/' ~ qemu_agent_snippet_filename] }} when: - vmid_config_check.rc != 0 or not vm_already_template | default(false) or ide2_removed.changed | default(false) diff --git a/tofu/nodito/main.tf b/tofu/nodito/main.tf index 1fba9a5..cc7a75d 100644 --- a/tofu/nodito/main.tf +++ b/tofu/nodito/main.tf @@ -9,9 +9,9 @@ resource "proxmox_vm_qemu" "vm" { target_node = var.proxmox_node vmid = try(each.value.vmid, null) - onboot = true - agent = 1 - clone = var.template_name + onboot = true + agent = 1 + clone = var.template_name full_clone = true vga { type = "serial0" @@ -22,7 +22,7 @@ resource "proxmox_vm_qemu" "vm" { cores = each.value.cores type = "host" } - memory = each.value.memory_mb + memory = each.value.memory_mb scsihw = "virtio-scsi-pci" boot = "c" @@ -42,18 +42,20 @@ resource "proxmox_vm_qemu" "vm" { } # Cloud-init: user, ssh keys, IP, and custom snippet for qemu-guest-agent - # Note: Using 'local' storage for snippets (not ZFS) as ZFS storage doesn't properly support snippet paths - ciuser = var.cloud_init_user - sshkeys = var.ssh_authorized_keys + # Note: Using vendor-data snippet (instead of user-data) allows Proxmox to automatically + # set the hostname from the VM name. User info is set separately via ciuser/sshkeys. + # Using 'local' storage for snippets (not ZFS) as ZFS storage doesn't properly support snippet paths + ciuser = var.cloud_init_user + sshkeys = var.ssh_authorized_keys ipconfig0 = try(each.value.ipconfig0, local.default_ipconfig0) - cicustom = "user=local:snippets/user-data-qemu-agent.yaml" + cicustom = "vendor=local:snippets/user-data-qemu-agent.yaml" # Disk on ZFS storage disk { - slot = "scsi0" - type = "disk" - storage = var.zfs_storage_name - size = "${each.value.disk_size_gb}G" + slot = "scsi0" + type = "disk" + storage = var.zfs_storage_name + size = "${each.value.disk_size_gb}G" # optional flags like iothread/ssd/discard differ by provider versions; keep minimal } diff --git a/tofu/nodito/variables.tf b/tofu/nodito/variables.tf index 95108db..30a1418 100644 --- a/tofu/nodito/variables.tf +++ b/tofu/nodito/variables.tf @@ -48,13 +48,13 @@ variable "ssh_authorized_keys" { variable "vms" { description = "Map of VMs to create" type = map(object({ - name = string - vmid = optional(number) - cores = number - memory_mb = number - disk_size_gb = number - vlan_tag = optional(number) - ipconfig0 = optional(string) # e.g. "ip=dhcp" or "ip=192.168.1.50/24,gw=192.168.1.1" + name = string + vmid = optional(number) + cores = number + memory_mb = number + disk_size_gb = number + vlan_tag = optional(number) + ipconfig0 = optional(string) # e.g. "ip=dhcp" or "ip=192.168.1.50/24,gw=192.168.1.1" })) default = {} }