Explaining snippets feature

Discussion in 'Proxmox VE: Installation and configuration' started by timota, Apr 19, 2019.

  1. timota

    timota New Member

    Joined:
    Oct 14, 2011
    Messages:
    9
    Likes Received:
    0
    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.
     
  2. mira

    mira Proxmox Staff Member
    Staff Member

    Joined:
    Feb 25, 2019
    Messages:
    109
    Likes Received:
    9
    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=...")
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. timota

    timota New Member

    Joined:
    Oct 14, 2011
    Messages:
    9
    Likes Received:
    0
    Great, thanks.

    Any plans to add support for subdirs and gui ?

    It will be awesome to choose which script to run from gui.

    Regards.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice