[SOLVED] Cloudinit setup for ubuntu-server 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?
 
Lots of great documentation is available on the official CloudInit website:

https://cloudinit.readthedocs.io

At first glance, the file you posted contains no entries that are suitable for "meta" section of CloudInit:
https://cloudinit.readthedocs.io/en/latest/reference/datasources/nocloud.html#example-meta-data

All of it looks like userdata.
I would recommend that you start with very simple files, one or two statements that would confirm for you that you configured everything properly and expand from there.

Good luck


Blockbridge: Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Thank you for spotting the error. I found the document very useful and seems like it is userdata.

Also, do cicustom "user=local:snippets/user-config.yaml" overwrite ciuser and cipassword ?
Second thing is /var/lib/vz/snippets/nocloud.yaml the right directory for cloudinit user config ?
 
Also, do cicustom "user=local:snippets/user-config.yaml" overwrite ciuser and cipassword ?
Once you assign anything "custom" , the built-in values no longer taken into consideration.
Second thing is /var/lib/vz/snippets/nocloud.yaml the right directory for cloudinit user config ?
If you havent changed anything in the storage definition, then yes.
https://pve.proxmox.com/wiki/Storage:_Directory


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

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!