Hi I have created the following script to create a VM and with a cloud-init config:
Then I have the following cloud-init.yml file
I generated the password hash using
What am I doing wrong? (How do I verify that my cloud init file was run?)
Bash:
#!/bin/bash
echo "Loading variables"
VMID=230
STORAGE=storage
IMAGE=debian-11-genericcloud-amd64.qcow2
SNIPPETNAME=debian-docker-cloud-init.yml
echo "VMID: $VMID"
echo "STORAGE: $STORAGE"
echo "IMAGE: $IMAGE"
echo "SNIPPETNAME: $SNIPPETNAME"
echo "Downloading image"
wget -P /tmp https://cloud.debian.org/images/cloud/bullseye/latest/$IMAGE
echo "Checking if VM exists"
VMSTATUS=$(qm status $VMID)
if [[ $? -eq 0 ]]
then
echo "VM already exists checking if its running"
if [[ "$VMSTATUS" = "status: running" ]]
then
echo "Stopping vm"
qm stop $VMID
fi
echo "Removing OS disk"
qm set $VMID --delete scsi1
qm set $VMID --delete unused0
else
echo "Creating vm"
qm create $VMID --name "debian-docker" --memory 10240 --sockets 1 --core 4 --net0 virtio="46:4A:5E:3C:8A:49",bridge=vmbr0 --description "Debian bullseye cloud image"
echo "Adding data disk"
qm set $VMID --scsi0 $STORAGE:64
echo "Adding cloud-init device"
qm set $VMID --ide2 $STORAGE:cloudinit
echo "Add vga serial"
qm set $VMID --serial0 socket --vga serial0
fi
echo "Importing OS disk"
qm importdisk $VMID /tmp/$IMAGE $STORAGE
echo "Removing image"
rm /tmp/$IMAGE
echo "Adding OS disk to vm"
qm set $VMID --scsihw virtio-scsi-pci --scsi1 $STORAGE:vm-$VMID-disk-1
echo "Resizing OS disk"
qm resize $VMID scsi1 +5G
echo "Installing cloud-init snippet"
cp cloud-init.yml /storage/snippets/snippets/$SNIPPETNAME
echo "Set cloud init config"
qm set $VMID --cicustom "user=snippets:snippets/$SNIPPETNAME"
echo "Set boot disk"
qm set $VMID --boot c --bootdisk scsi1
echo "Starting vm"
qm start $VMID
Then I have the following cloud-init.yml file
YAML:
hostname: debian-docker
manage_etc_hosts: true
ssh:
install-server: true
allow-pw: true
disable_root: false
ssh_quiet_keygen: true
allow_public_ssh_keys: true
chpasswd:
expire: False
users:
- default
- name: peter
gecos: peter
groups: adm, users, sudo, docker
lock_passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
passwd: "$6$qwdd8gt3bTs2HGut$FwwV5Q4kNycOipS0VMctcaJY06uVChnd8ST5TFtsioex1y9yWLKj.LreUm0r0x8fqldNM6sx5n.QctlaxGUBl1"
- name: root
lock_passwd: false
hashed_passwd: "$6$qwdd8gt3bTs2HGut$FwwV5Q4kNycOipS0VMctcaJY06uVChnd8ST5TFtsioex1y9yWLKj.LreUm0r0x8fqldNM6sx5n.QctlaxGUBl1"
I generated the password hash using
echo peter| mkpasswd -m sha-512 -s
but no matter what I do I can't login, not with the terminal in proxmox and not using ssh (putty).What am I doing wrong? (How do I verify that my cloud init file was run?)