Custom Cloud Init Config in Proxmox VE

From Thomas-Krenn-Wiki
Jump to navigation Jump to search

If you want to use Custom-ID (Custom Cloud-Init) parameters in Proxmox VE, you have to note the following things:

  • creation of a snippet directory
  • definition of the snippet directory as datastore in the Proxmox VE Web-UI
  • creation in the custom cloud init files (z.B. ci-user-90000.yml)
  • reference of the CI custom file within the VM definition

Hint: We have presented Cloudinit in a beginners´ seminar: https://www.youtube.com/watch?v=EKn7lTJrOW8&t

Creation Snippet directory

Proxmox VE requires for the transfer of CI custom information the corresponding Cloud Init files in a defined storage for snippets. This can be created as follows:

 root@PMX7:~# mkdir /mnt/pve/cephfs/cloud-init

In this register, the snippets for Cloud Init configurations will be created. After this, the register must be added via Web-UI as datastore for snippets.

Important: for Cluster systems: so that the VMs stay Cloud Init Drive HA able, the snippets must be dropped on a central storage for example cephfs so that they are, depending on the fail scenario, available on every node for the starting of the VMs.

If the custom CI config is on a local data store, the VM can not be started on other servers, as the Config reference is therefore invalid.

Custom CI Config Files

important hint: as soon as you define custom CI parameters, the cloud init parameters from the Proxmox VE Web UI no longer apply. Edit 27.06.2024: It seems that you can combine the two options (Web-UI parameters) and Custom-CI. It is not possible to say how useful this is and whether this will change in the future. Ultimately, the custom CI file always has priority.


VM can be configured via multiple Cloud-Init files: https://pve.proxmox.com/wiki/Cloud-Init_Support#_cloud_init_specific_options

meta=<volume>
Specify a custom file containing all meta data passed to the VM via" ." cloud-init. This is provider specific meaning configdrive2 and nocloud differ.

network=<volume>
To pass a custom file containing all network data to the VM via cloud-init.

user=<volume>
To pass a custom file containing all user data to the VM via cloud-init.

vendor=<volume>
To pass a custom file containing all vendor data to the VM via cloud-init

These can be created at will. This is followed by an example configuration:

Vendor File

The vendor file is now performed and considered for the first boot of the VM resource.

root@PMX7:/mnt/pve/cephfs/cloud-init/snippets# nano ci-vendor-90000.yml

#cloud-config
runcmd:
    - apt update
    - apt install -y qemu-guest-agent
    - systemctl start qemu-guest-agent
    - reboot

Network File

The network file defines the network configuration of the system. More details can be found in the Cloud-Init documentation: https://cloudinit.readthedocs.io/en/23.4.1/reference/network-config-format-v2.html

We took a configuration of 2 network adapters including manual static routes as an example.

root@PMX7:/mnt/pve/cephfs/cloud-init/snippets# cat ci-network-90000.yml
#
network:
  version: 2
  ethernets:
    ens18:
      dhcp4: true
    ens19:
      dhcp4: no
      addresses:
       - 192.168.99.10/24
      nameservers:
        addresses: [192.168.110.61]
      routes:
        - to: 192.168.99.0/24
          via: 192.168.99.1
          metric: 3

User File

The User-File defines other settings, for example the hostname, the default-user, SSH-Keys or the installation of packages.

root@PMX7:/mnt/pve/cephfs/cloud-init/snippets# cat ci-user-90000.yml
#cloud-config
hostname: ubuntu2404-ci
manage_etc_hosts: true
user: tk
ssh_authorized_keys:
  - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD= tkag\jsterr@Standard-150
  - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC= tkag\jsterr@Standard-020
chpasswd:
  expire: False
users:
  - default
locale: de_DE.UTF-8
timezone: Europe/Berlin
runcmd:
  - echo "Hello World Test" > test.txt
packages:
  - qemu-guest-agent
  - docker.io

Setting of Custom CI Config

After you have created the desired files, you can now add them to the desired VM using the command line:

root@PMX7:/mnt/pve/cephfs/cloud-init/snippets# qm set 90000 --cicustom "user=ci-snippets:snippets/ci-user-90000.yml,vendor=ci-snippets:snippets/ci-vendor-90000.yml,network=ci-snippets:snippets/ci-network-90000.yml"

Starting of VM mit Custom CI Config

After setting of the configuration, the VM can be started and it uses only the above referenced custom Cloud-Init-configuration, which does the following in our case:

  • setting of hostname (ubuntu 2404-ci)
  • state SSH Keys
  • network is configured(ens18 and ens19)
  • updates are imported and the server is then rebooted
  • User creation of Users tk
  • define localities (de_DE.UTF-8)
  • setting of Timezone (Europe / Berlin)
  • create a file text.txt and fill it with "Hello World Test"
  • The packages qemu-guest-agent and "docker.io" are installed


Author: Jonas Sterr

Jonas Sterr has been working for Thomas-Krenn for several years. Originally employed as a trainee in technical support and then in hosting (formerly Filoo), Mr. Sterr now mainly deals with the topics of storage (SDS / Huawei / Netapp), virtualization (VMware, Proxmox, HyperV) and network (switches, firewalls) in product management at Thomas-Krenn.AG in Freyung.


Translator: Alina Ranzinger

Alina has been working at Thomas-Krenn.AG since 2024. After her training as multilingual business assistant, she got her job as assistant of the Product Management and is responsible for the translation of texts and for the organisation of the department.


Related articles

Chrony Faster Time Sync Configuration
Proxmox upload ISO image
ZFS Pool Import - Proxmox single host reinstall without full backup