hostname works

This commit is contained in:
counterweight 2025-11-02 01:48:07 +01:00
parent d4782d00cc
commit 9d43c19189
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
3 changed files with 25 additions and 24 deletions

View file

@ -78,15 +78,14 @@
set_fact: set_fact:
ssh_keys_list: "{{ ssh_key_content.content | b64decode | split('\n') | select('match', '^ssh-') | list }}" 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: copy:
dest: "{{ zfs_pool_mountpoint }}/snippets/{{ qemu_agent_snippet_filename }}" dest: "{{ zfs_pool_mountpoint }}/snippets/{{ qemu_agent_snippet_filename }}"
mode: '0644' mode: '0644'
content: | content: |
#cloud-config #cloud-config
user: {{ proxmox_ciuser }} # Vendor-data snippet: Proxmox will automatically set hostname from VM name when using vendor-data
ssh_authorized_keys: # User info (ciuser/sshkeys) is set separately via Terraform/Proxmox parameters
{{ ssh_keys_list | to_nice_yaml | indent(10, first=True) }}
package_update: true package_update: true
package_upgrade: true package_upgrade: true
packages: packages:
@ -164,7 +163,7 @@
] ]
+ (proxmox_ci_upgrade | bool + (proxmox_ci_upgrade | bool
| ternary(['--ciupgrade 1'], [])) | ternary(['--ciupgrade 1'], []))
+ ['--cicustom user=local:snippets/' ~ qemu_agent_snippet_filename] + ['--cicustom vendor=local:snippets/' ~ qemu_agent_snippet_filename]
}} }}
when: when:
- vmid_config_check.rc != 0 or not vm_already_template | default(false) or ide2_removed.changed | default(false) - vmid_config_check.rc != 0 or not vm_already_template | default(false) or ide2_removed.changed | default(false)

View file

@ -9,9 +9,9 @@ resource "proxmox_vm_qemu" "vm" {
target_node = var.proxmox_node target_node = var.proxmox_node
vmid = try(each.value.vmid, null) vmid = try(each.value.vmid, null)
onboot = true onboot = true
agent = 1 agent = 1
clone = var.template_name clone = var.template_name
full_clone = true full_clone = true
vga { vga {
type = "serial0" type = "serial0"
@ -22,7 +22,7 @@ resource "proxmox_vm_qemu" "vm" {
cores = each.value.cores cores = each.value.cores
type = "host" type = "host"
} }
memory = each.value.memory_mb memory = each.value.memory_mb
scsihw = "virtio-scsi-pci" scsihw = "virtio-scsi-pci"
boot = "c" boot = "c"
@ -42,18 +42,20 @@ resource "proxmox_vm_qemu" "vm" {
} }
# Cloud-init: user, ssh keys, IP, and custom snippet for qemu-guest-agent # 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 # Note: Using vendor-data snippet (instead of user-data) allows Proxmox to automatically
ciuser = var.cloud_init_user # set the hostname from the VM name. User info is set separately via ciuser/sshkeys.
sshkeys = var.ssh_authorized_keys # 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) 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 on ZFS storage
disk { disk {
slot = "scsi0" slot = "scsi0"
type = "disk" type = "disk"
storage = var.zfs_storage_name storage = var.zfs_storage_name
size = "${each.value.disk_size_gb}G" size = "${each.value.disk_size_gb}G"
# optional flags like iothread/ssd/discard differ by provider versions; keep minimal # optional flags like iothread/ssd/discard differ by provider versions; keep minimal
} }

View file

@ -48,13 +48,13 @@ variable "ssh_authorized_keys" {
variable "vms" { variable "vms" {
description = "Map of VMs to create" description = "Map of VMs to create"
type = map(object({ type = map(object({
name = string name = string
vmid = optional(number) vmid = optional(number)
cores = number cores = number
memory_mb = number memory_mb = number
disk_size_gb = number disk_size_gb = number
vlan_tag = optional(number) vlan_tag = optional(number)
ipconfig0 = optional(string) # e.g. "ip=dhcp" or "ip=192.168.1.50/24,gw=192.168.1.1" ipconfig0 = optional(string) # e.g. "ip=dhcp" or "ip=192.168.1.50/24,gw=192.168.1.1"
})) }))
default = {} default = {}
} }