Explaining snippets feature

timota

Renowned Member
Oct 14, 2011
9
2
68
Hi all,

recently i discovered that Proxmox now supports great feature - snippets, aka hookscript. Also, it has special content storage type - snippets to hold snippets.

But im curious how they can be used from Web GUI.

Do i need to create hookscript and store it on storage type "snippets" with a special name (vm name) ?
Or do i need to directly edit "vm.conf" files to include hookscript as i could not find any options in GUI.

If this option only supported from CLI and during manually invoking "start" - it useles for daily usage, only for automation/scripting. I mean useles - that if something happens with node and VM has to migrate to another one but we need to prepare ENV before (start some tools, fw, etc) - cluster cant run hook script automatically - admin intervention needed.


Can you please explain more on this feature: how it can be configured ?

Regards.
 
Currently it's only possible to add a hookscript via CLI. hookscripts have to be on a 'snippets'-capable storage. All you have to do is create a script in the snippets directory (for the default 'local' storage it is /var/lib/vz/snippets), but subdirectories are not supported. Choose whatever name fits the file and add it via 'qm set --hookscript <storage>:snippets/<file>'. The same applies to containers and 'pct'.
The actions defined in the script are always executed, no matter if started automatically or manually. You have to make sure the script is executable.
If you want to migrate the VM, make sure the hookscript is available on the target node as well. (<storage>:snippets/<file> as configured for the VM/CT has to be available on all nodes you want to migrate to)

In addition snippets can be used to replace the generated cloud-init files ('network', 'user', 'meta', this is undocumented for now). This allows workarounds such as adding a route to a gateway that is not in the subnet on Ubuntu VMs (requires options not supported by cloud-init, but the yaml file is just passed through to netplan because the cloud-init network config is a subset of the netplan config).
You can do this with the following command: 'qm set --cicustom "network=<storage>:snippets/<file>"' where 'network' can be replaced with 'user' or 'meta' and they can be mixed by separating them with a comma. ("user=...,meta=..." or "network=...,user=...,meta=...")
 
  • Like
Reactions: djfreak
Some examples could be useful.

There is no information about custom config and used hookscripts in VM info/options page (via web interface).
View is essential, edit is very desirable.
 

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!