Basic customization with Cloud-init

MichalTill

New Member
Feb 24, 2023
5
1
1
Newbie question: I have a working bash script that creates a Cloud-init'ed VM via bunch of `qm` and `virt-customize` commands. Now I would like to customize the final state via Cloud-init YAML file (users, packages, files etc.). Beacause I am new to Proxmox and CI, I totally struggle with where to put the YAML file on the guest machine. Some examples operate with `/etc/cloud/cloud.cfg`, some with `snippets/vendor.yaml`, some with other places. I googled CI docs through and through, but fail to grasp this simple thing - where the YAML config (configs?) go.

Can you please point me to the right direction and what in bash script should I do with a YAML file so it gets processed by Cloud-init and machine is set accordingly?
 
  • Like
Reactions: stephane-klein
I totally struggle with where to put the YAML file on the guest machine
You dont generally "put" the file on guest machine. You feed the file via a method available in your cloud. For PVE its via "cicustom" (man qm).
`/etc/cloud/cloud.cfg`
This is a default location of generic Cloud Image that you can download from one of the Linux Vendors. This is where OS defaults are stored. Certainly, if you are building your Image from scratch - you can put as many common default variables there as you want.
with `snippets/vendor.yaml`
"snippets" is a PVE terminology. It's a location where you can put various configuration files.

By default, you can place them in /var/lib/vz/snippets (https://pve.proxmox.com/wiki/Storage:_Directory)
Or, if you have other FILE-based storage - you can place it there. Of course, you have to mark that storage pool as "available for snippets", as well as create an appropriate directory structure.

YML files placed in that structure must be specified via "cicustom" and will be fed via special ISO to your VM during boot.
Normally, you would place any customization there that is above your default config.

Note, that the procedure above is PROXMOX specific. Other clouds/hypervisors will operate differently.

https://pve.proxmox.com/wiki/Cloud-Init_Support



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
You dont generally "put" the file on guest machine. You feed the file via a method available in your cloud. For PVE its via "cicustom" (man qm).



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

Aha! So my my script will put the config yaml to /var/lib/vz/snippets/vendor.yaml, which is in fact local:snippets/vendor.yaml and it is fed with
Code:
qm set $VMID --cicustom "vendor=local:snippets/vendor.yaml"
?
 
This is a default location of generic Cloud Image that you can download from one of the Linux Vendors. This is where OS defaults are stored. Certainly, if you are building your Image from scratch - you can put as many common default variables there as you want.
Then, what does this in general do? Exactly what config is this?

Code:
echo "### Copying Proxmox Cloud-init config to image ###"
virt-customize -a $DISK_IMAGE --upload ${CURRENT_DIR}/cloud.cfg:/etc/cloud/cloud.cfg
 
yes
Then, what does this in general do? Exactly what config is this?
Why not download one of the Cloud images from (Ubuntu, Debian, Rocky, Almalinux, etc) and examine it?

Or plug it into search and examine pages such as:
https://docs.redhat.com/en/document...init-configuration_introduction-to-cloud-init

Or check github?
https://github.com/canonical/cloud-init/tree/main/config

Good luck


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!