[SOLVED] [HELP] Something wrong with cloud init?

Freeness8085

Member
Apr 15, 2023
19
2
8
Hi!

Learning to deploy machines with cloud init. I create the a machine with the following commands:

Bash:
#!/bin/bash
# With this script we create an automated template

# Install all required tools
sudo apt update -y
sudo apt install libguestfs-tools -y

# Download image
sudo wget http://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2

# Install packages
sudo virt-customize -a debian-12-generic-amd64.qcow2 --install sudo,apt-transport-https,ca-certificates,curl,gnupg2,software-properties-common,qemu-guest-agent

# Users and changes
sudo virt-customize -a debian-12-generic-amd64.qcow2 --root-password password:superpassword
sudo virt-customize -a debian-12-generic-amd64.qcow2 --hostname phobos.lan

# Create the templates folder

sudo mkdir -p /var/lib/vz/template/qcow
sudo cp debian-12-generic-amd64.qcow2 /var/lib/vz/template/qcow/


# machine configuration



sudo qm create 9000 --name debian12-cloudinit --net0 virtio,bridge=vmbr0,tag=200 --scsihw virtio-scsi-pci
sudo qm set 9000 --scsi0 sdd-data:0,discard=on,ssd=1,format=raw,import-from=/var/lib/vz/template/qcow/debian-12-generic-amd64.qcow2
sudo qm disk resize 9000 scsi0 32G
sudo qm set 9000 --bios ovmf --efidisk0 sdd-data:1,format=raw,efitype=4m,pre-enrolled-keys=1
sudo qm set 9000 --boot c --bootdisk scsi0
sudo qm set 9000 --cpu host --cores 4 --memory 4096
sudo qm set 9000 --agent enabled=1
sudo qm set 9000 --ide2 sdd-data:cloudinit
sudo qm template 9000

Everything works fine, and the template is created. Then I clone the template but:

1. The dhcp client is installed, but does not run in startup, i have to manually run it (dhclient)
2. Even when i do run it and it gets an IP, it looks like the DNS is not working (temporary failure on name resolution)

It is NOT a DHCP issue, the DHCP server runs perfectly fine for traditional, manually created virtual machines.

Am I missing something? Do i have to install additional packages on the image and enable dhclient on startup?

Thanks!

EDIT: Even more weird, resolv.conf is a symlink managed by systemd-resolved but systemd-resolved is not installed as a service...
EDIT2: I found a forum post that seemd to solve the issue...does not work for me: https://forum.proxmox.com/threads/debian-12-1-cloud-image-template-network-problem.131160/
 
Last edited:
You are using OVMF bios with IDE cloudinit. Last time I checked this combination was not compatible.
If you check your booted image you should find no CDROM , and cloud-init logs empty.

Change your cloudinit to SCSI and redo your experiment.

good luck



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Well now it works:

Bash:
#!/bin/bash
# With this script we create an automated template
vmhostname="test.lan"
vmtimezone="Europe/Madrid"
template_url="https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.raw"
template_name="debian-12-generic-amd64.raw"
vm_id=6000
vm_name="test.lan"
wget $template_url
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDFU6vvLmFklGnyO3z0tzBznpA7lsfyB1TpCWT/23NnZHIA08fXI2x+XzAeKOmxAmzt7AoHVQo0bOFqGkq58+020t4oI8xq0fUvYfNdPfvzrXt0+pQAaGg8KyoB1+ZC4Oh6mJxQg2pPjVdNXn6C+CeV/aUbJOtGuRPtXIl15poyPtageY4h7/X4WRJubLdiL6wOr3VxL5xu3lEtYyMoO2hzhNcOey6PUAsITpwMaMy8pcfEar9f8gPV2W42E49cxWoY0BX3lthIef18ScBDyZYxM9JGvjgLIDXsAYQP0AvqGmzLrtkNJ9hMJXC26Y8CQD+tG6ZL3lz9IOkwN6PHQNhD6o8sylkqJI9oxKn/ldXiFXOOBYpozvD/ZX9TI6BXYnS8iea3zJ0FR2N9+JPsjMwfjuPbGFKQknJYCm80LSR709sJQdlLTnU69P1nlja6uc4UvLnIMuQGb098ziUTIbNqmGKqzD25byFgtWwQmvc9qsqZpUmfxcfuXZsuw0Tie+GezExxSVlzMMLrcPltnXJzvAlemMbvoH9Q7OLtijYBiqF9Pe1h+ZnwL09LklSpGk53rD3qfEgwBbW63MvA4W+sIPWn/lj3+KrDYm0kM+5c3IWtZK9Axh6/xFp+j68RSInOjsYHb6mO+7Pu5P5lE2SH9t9bzNB7ArzzawDHw9hRZw== confmanager@ansible" > key_id_rsa.pub
virt-customize -a "$template_name" --install qemu-guest-agent
virt-customize -a "$template_name" --run-command "useradd confmanager"
virt-customize -a "$template_name" --run-command "mkdir -p /home/confmanager/.ssh"
virt-customize -a "$template_name" --ssh-inject confmanager:file:key_id_rsa.pub
virt-customize -a "$template_name" --root-password password:superpassword
virt-customize -a "$template_name" --hostname $vmhostname
virt-customize -a "$template_name" --timezone Europe/Madrid

qm create "$vm_id" --name "$vm_name" --net0 virtio,bridge=vmbr0,tag=200 --scsihw virtio-scsi-pci --machine q35
qm set "$vm_id" --scsi0 sdd-data:0,discard=on,ssd=1,format=raw,import-from=/root/$template_name
qm disk resize "$vm_id" scsi0 32G
qm set "$vm_id" --boot order=scsi0
qm set "$vm_id" --cpu host --cores 4 --memory 4096
qm set "$vm_id" --bios ovmf --efidisk0 sdd-data:1,format=raw,efitype=4m,pre-enrolled-keys=1
qm set "$vm_id" --ide2 sdd-data:cloudinit
qm set "$vm_id" --agent enabled=1
qm set "$vm_id" --ipconfig0 ip=dhcp
rm key_id_rsa.pub
rm "$template_name"

But now I have another issue. When I run this command:


Bash:
qm set "$vm_id" --cicustom "/var/lib/vz/snippets/generic_cloudinit_user_debian.yaml"

The yaml file has thsi content, but essentially ANY yaml file for cloud int fails:

Bash:
qm set 6000 --cicustom /var/lib/vz/snippets/generic_cloudinit_user_debian.yaml
400 Parameter verification failed.
cicustom: invalid format - value without key, but schema does not define a default key

Yaml's content:

YAML:
#cloud-config
hostname: ubuntu20
manage_etc_hosts: true
user: user
ssh_authorized_keys:
  - ssh-rsa AAAAKEYHEEEEREEEE= user@client
chpasswd:
  expire: False
users:
  - default
package_upgrade: true
package_reboot_if_required: true
locale: en_GB.UTF-8
timezone: Europe/Berlin
runcmd:
  - sed -i 's/[#]*Port 22/Port 9726/g' /etc/ssh/sshd_config
  - sed -i 's/[#]*PermitRootLogin yes/PermitRootLogin prohibit-password/g' /etc/ssh/sshd_config
  - sed -i 's/[#]*PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
  - sed -i 's/#HostKey \/etc\/ssh\/ssh_host_ed25519_key/HostKey \/etc\/ssh\/ssh_host_ed25519_key/g' /etc/ssh/sshd_config
  - systemctl reload ssh
packages:
  - qemu-guest-agent
  - docker.io

Even if I set up the yaml to the bare minimum:
YAML:
#cloud-config
timezone: "America/Los_Angeles"

Any ideas?
 
Last edited:
I reply myself: you have to configure proerply the snippets location and also, call it properly:

Create a snippets folder on Proxmox:

Bash:
pvesm set local --content images,rootdir,vztmpl,backup,iso,snippets

Copy snippets file there.

Apply them:

Bash:
qm set 6000 --cicustom "vendor=local:snippets/vendor.yaml"