how to use "standard"-cloudinit (user-data) via cli?

vec0

New Member
Jan 30, 2024
9
1
3
I have some services which I deploy using cloud-init on another virtualization environment.
Now I need to move to proxmox and smh need to reuse the same logic to deploy VMs.

I need it to be possible to deploy vm's with my cloud-init data as I used before. not just passign a username & password but variables and scripts via CLI.

# nice to have:
Even greater would be if someone has a CLI which works using the API and smh already includes some logic to distribute the VMs accordingly to the current usage of ressources of hosts in a cluster :)


this is how I passed data using cloudinit "user-data" as a .yaml file before:

```
#cloud-config
users:
- name: adminuser
sudo: ALL=(ALL) NOPASSWD:ALL
groups: sudo
shell: /bin/bash

chpasswd:
list: |
root:myPW
adminuser:myPW
expire: False

ssh_pwauth: true
disable_root: false

write_files:
- path: /root/init_script.sh
permissions: '0755'
content: |
#!/bin/bash

# Variables
timedatectl set-timezone Europe/Amsterdam
export myDOMAIN="mydomain.tld"
export myUSERCOUNT="100"
export CloudFlareAPITOKEN="myCloudFlareAPITOKEN"
# custom colors
export AK_ACCENT_NEW="#76b728"

# Monitoring & initSetupDL
export monitoring_cloudinit="https://monitor.mydomain.tld/api/push/WM9XqoCVyX?status=up&msg="
export initSetupDL="https://nc.mydomain.tld/index.php/s/gqEbGdDSGE7ZkbN"
# DL_from_NC
wget -O "DL_from_NC.sh" "$initSetupDL/download?path=&files=DL_from_NC.sh"
source DL_from_NC.sh

# START OF SCRIPTS
systemctl enable --now qemu-guest-agent.service
# Setup Scripts
DL_from_NC Portal_SSO_init.sh
yes | bash ./Portal_SSO_init.sh -x
rm ./Portal_SSO_init.sh
DL_from_NC Portal_SSO_API.sh
yes | bash ./Portal_SSO_API.sh -x
rm ./Portal_SSO_API.sh
DL_from_NC Portal_SSO_design.sh
yes | bash ./Portal_SSO_design.sh -x
rm ./Portal_SSO_design.sh
update
wget "$monitoring_cloudinit$myDOMAIN PORTAL SSO DONE"

runcmd:
- bash /root/init_script.sh

package_update: true
packages:
- qemu-guest-agent
```
 

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!