[SOLVED] vApp Options in proxmox

fadeway

New Member
Oct 30, 2024
9
1
3
VMWare ESXi has a feature called "vApp Options" which can be used to pass arguments to the guest. For example when cloning VMs from a template, vApp Options can used to differentiate the newly created VM instances.

Has anyone tried to achieve a similar effect in proxmox? Do you just ssh into the VMs and manually configure them or can arbitrary parameters somehow be passed as part of the VM definition? Maybe with cloud-init?
 
I got it implemented with cloud-init. Key points if someone else needs to do this:
  1. A cloud-init drive has to be added, for example in my call for creating the VM I define a disk with this line: ide2: "{{ vm_storage }}:cloudinit"
  2. The cloud-init YAML has to be uploaded over a side channel. It needs to be on a storage with snippets enabled. Once you enable snippets, proxmox will create a folder called "snippets/" on the storage. As far as I can tell, the YAML must be exactly in that folder. Placing it in a subfolder will cause proxmox to throw errors when you try to add it to VM.
  3. You tell proxmox to use the uploaded yaml with the cicustom parameter of the qemu/<vm_id>/config API endpoint. For example I do:
Code:
    - name: Set cloud-init options on cloned VM
      ansible.builtin.uri:
        url: "https://{{ api_host }}:8006/api2/json/nodes/{{ node }}/qemu/{{ vm_id }}/config"
        method: PUT
        headers:
          Authorization: "{{ proxmox_auth_cookie }}"
        body:
          cicustom: "user={{ storage }}:snippets/cloud_init.user"
        body_format: json
        status_code: 200

Before using the API, it helps to test directly on the proxmox host with sudo qm set <vm_id> --cicustom "user=<storage>:snippets/cloud_init.user"


Example YAML to use for testing:

Code:
#cloud-config
hostname: worksworks
write_files:
- content: |
    # My new /etc/sysconfig/samba file
    SMBDOPTIONS="-D"
  path: /etc/cloud-init-test
  owner: root:root
  permissions: '0644'
 
Last edited:
  • Like
Reactions: Johannes S