Cloud-init setup problem

shalevlau

New Member
Jan 2, 2024
4
0
1
I want to appreciate for proxmox's open source.
I want to automate ubuntu server using cloudinit nocloud script but i have no idea how to set it up. especially there is no resource about it on google.
Below is my setup:

cloudinit assignment to the qemu machine
Bash:
qm set 150 \
    --cicustom "meta=local:snippets/nocloud.yaml"\
    --citype nocloud

The code is save in local storage (/var/lib/vz/snippets/nocloud.yaml) and but ubuntu server doesnt run my script
YAML:
packages:
  - qemu-guest-agent
package_update: true
package_upgrade: true
package_reboot_if_required: true
hostname: heyser
bootcmd:
  - sudo su
  - apt update && apt upgrade
  - apt-get remove docker docker-engine docker.io containerd runc
  - apt install samba
  - apt-get install docker.io --dry-run
runcmd:
  - sudo su
  - ## ssh port and root
  - ufw allow 522/tcp
  - sed -i 's/[#]*Port 22/Port 522/g' /etc/ssh/sshd_config
  - sed -i 's/[#]*PermitRootLogin yes/PermitRootLogin prohibit-password/g' /etc/ssh/sshd_config
  - systemctl reload sshd
  - ## swap
  -   fallocate -l 4G /swap.img
  -   mkswap /swap.img
  -   swapon /swap.img
  - ## https://docs.docker.com/config/daemon/remote-access/
  - fragment_path=$(systemctl show -p FragmentPath docker.service | awk -F= '{print $2}')
  - sed -i 's|ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock|ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0:2375|' $fragment_path
  - systemctl daemon-reload
  - systemctl restart docker
  - ## mount disk
  - mkdir /media/new
  - echo -e "$(lsblk -o NAME,FSTYPE,UUID,LABEL | grep 'new-harddisk' | awk '{print "UUID="$3" /media/new "$2" defaults 0 2"}')" | sudo tee -a /etc/fstab
  - ## SMB
  - echo -e "\n[new]\n    path = /media/new\n    read only = no\n    browseable = yes\n    create mask = 0777\n    directory mask = 0777\n" | sudo tee -a /etc/samba/smb.conf
  - service smbd restart
  - sudo ufw allow samba
  - # sudo smbpasswd -a newuser#Username used must belong to a system account
  - sudo shutdown -r now

The proxmox default ciuser and cinetwork work perfectly for me but not custom script
Any one done cloudinit automation before?
 
Last edited: