Skip to content

Proxmox Cloud Init

Option 1 : qemu

qemu

https://github.com/jdedev/homelab_proxmox/tree/main/qemu

#!/bin/bash

# qm_destroy.sh
vmId=8100
vmIdClone=8101

# cd /mnt/pve/nas.iso/images
# download image Ubuntu 22.04 (Jammy Jellyfish)
# wget -O jammy-server-cloudimg-amd64.img https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img

qm list
qm stop $vmIdClone
qm destroy $vmIdClone 
qm destroy $vmId 

qm list
qm create $vmId --memory 2048 --core 2 --name ubuntu-cloud --net0 virtio,bridge=vmbr0
qm importdisk $vmId /mnt/pve/nas.iso/template/iso/jammy-server-cloudimg-amd64.img nas.vmpool1 --format qcow2
qm set $vmId --scsihw virtio-scsi-pci --scsi0 /mnt/pve/nas.vmpool1/images/$vmId/vm-$vmId-disk-0.qcow2
qm set $vmId --ide2 nas.vmpool1:cloudinit
qm set $vmId --boot c --bootdisk scsi0
qm set $vmId --serial0 socket --vga serial0
qm template $vmId
qm clone $vmId $vmIdClone --name=vm1
qm set $vmIdClone --sshkeys ~/.ssh/id_ed25519.pub
qm set $vmIdClone --ipconfig0 "gw=10.0.0.139,ip=10.0.5.1/20"
qm set $vmIdClone --cipassword=!@PRw08jde
qm set $vmIdClone --agent 1
qm set $vmIdClone --cicustom "vendor=nas.iso:snippets/31_cloud_config.yml"
# cd /root/git/homelab_proxmox

Retrieve ubuntu image

# open proxmox cloud init folder
cd /mnt/pve/nas.iso/images/
cd 
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
  • ubuntu-2204-jammy.yml
    #cloud-config
    hostname: ubuntu20
    manage_etc_hosts: true
    user: user
    ssh_authorized_keys:
      - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEzzVizJPOg3WBRlUQ9cyE9/WE4CitnPAj32EWOiXXZb [email protected]
    chpasswd:
      expire: False
    users:
      - default
    package_upgrade: true
    package_reboot_if_required: true
    locale: en_GB.UTF-8
    timezone: Australia/Melbourne
    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
    
qm create 8000 --memory 2048 --core 2 --name ubuntu-2204-jammy --net0 virtio,bridge=vmbr0
qm importdisk 8000  /mnt/pve/nas.iso/template/iso/jammy-server-cloudimg-amd64.img nas.vmpool2 --format qcow2
qm set 8000 --scsihw virtio-scsi-pci --scsi0 /mnt/pve/nas.vmpool2/images/8000/vm-8000-disk-0.qcow2
qm set 8000 --ide2 nas.vmpool2:cloudinit
qm set 8000 --cicustom "user=local:cloud-init/9001-cloud-init.yml"
qm set 8000 --boot c --bootdisk scsi0
qm set 8000 --serial0 socket --vga serial0
qm set 8000 --cicustom "user=local:cloud-init//mnt/pve/nas.iso/snippets/ubuntu-2204-jammy.yml"

Option 2 : terraform

https://github.com/jdedev/homelab_proxmox/tree/main/terraform

Referencies

https://github.com/jdedev/homelab_proxmox https://docs.technotim.live/posts/cloud-init-cloud-image/
https://github.com/chris2k20/proxmox-cloud-init