Proxmox Cloud-init with custom UserData

From DWIKI

Create the template

qm create 9000 --memory 2048 --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci
qm set 9000 --scsi0 local-lvm:0,import-from=/var/lib/vz/template/iso/noble-server-cloudimg-amd64.img
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --boot order=scsi0
qm template 9000

Enable snippets on your storage

Datastore->local (or whatever storage you want to use) -> edit and tag "snippets"

Create UserData file

create file /var/lib/vz/snippets/ansible.yaml containing

#cloud-config
ssh_pwauth: false
users:
- name: ansible
  gecos: Ansible User
  groups: users,admin,wheel
  sudo: ALL=(ALL) NOPASSWD:ALL
  shell: /bin/bash
  lock_passwd: true
  ssh_authorized_keys:
    - ssh-rsa AAAAB3

NOTE: this is yaml, so check your indentation :)


Clone the template

qm clone 9000 131 --name ansibletest qm set 131 --cicustom "user=pbs-saspool:snippets/ansible.yaml" qm set 131 --ipconfig0 ip=192.168.100.131/24,gw=192.168.100.15