xo-cli cloud-init
-
Hi guys, this might be a dumb question but I've been pulling my hair out all day and I have a feeling that the solution is simple, I probably just have something misconfigured. I am trying to deploy a VM from a template configured with Cloud-init using the Xen Orchestra cli as part of a bash script to test some automation stuff. When I deploy using the Xen Orchestra GUI, the Cloud Config/Network Config files that I use work perfectly to deploy the VM exactly as I expect them to.
However, when I try to do the same using the xo-cli (and using the same Cloud Config/Network Config files that I use in the GUI) the VM is created successfully, but none of the networking configuration is applied. The VM that is created does not have any IP address, even the static address that was assigned to the template. Here is an example of the xo-cli command that I run:
xo-cli vm.create bootAfterCreate=true cloudConfig="/root/user.yaml" networkConfig="/root/network.yaml" clone=true name_label="Test VM" template=0856a8d6-9183-f39d-f968-290b18a1bd42 VIFs='json:[{"network":"ca96456f-3843-26f5-7075-1e54f70d8f97"}]' hvmBootFirmware=bios copyHostBiosStrings=true
I have read that NoCloud looks for a Base64 string for the cloud/network configuration, so I have tried both the raw yaml file and a Base64 encoded version, and both give the same results. Here are my config files, that DO work when creating the VM from the Xen Orchestra GUI, but not when using the CLI
Cloud Config:
#cloud-config hostname: test packages: - htop - iotop - hdparm - vim - strace - inotify-tools - rsync - git - jq
Network Config:
network: version: 1 config: - type: physical name: eth0 subnets: - type: static address: 192.168.11.100/24 gateway: 192.168.11.1 dns_nameservers: - 8.8.8.8 - 8.8.4.4
Am I missing something on how I am supposed to pass this information in the xo-cli command? Any help would be GREATLY appreciated.
I am on XCP-ng version 8.2.1 and Xen Orchestra is commit 3d054
-
Hi,
Have you searched in here? I vaguely remember someone else doing the same and asked for how to do it with the CLI (but I don't remember where exactly). Otherwise, @julien-f might help.
-
@AdamG XO's
vm.create
creates a disk containing the files expected (meta-data
&user-data
) by Cloud Init, nothing else.
It is up to the VM template to have Cloud Init installed and to look for the files at the right place.The params
cloudConfig
andnetworkConfig
must contain the configs themselves forvm.create
to put into the related files, not paths. -
Hi @julien-f,
Thank you for the rapid response! Just to clarify a bit further, when I run the xo-cli command as above, the VM is created and the XO CloudConfigDrive is created and attached to the VM, just the same as if I did so in the GUI.
Based on your response, it seems my problem may be in the data I have supplied to the cloudConfig and networkConfig parameters. If I understand correctly, I need to pass the actual data that would be input into the config fields in the GUI, and not paths to the files themselves. Can you possibly give me an example of what that might look like? I am just having a little trouble understanding how to pass this information properly while maintaining the yaml structure (if this is even necessary?).
Once again, thank you for your help thus far. Looking forward to hearing from you!
-
Hi @julien-f @olivierlambert ,
I was actually able to finally figure out what I was doing wrong this whole time! I want to update this thread so that anyone else facing the same issue as me in the future can learn from my mistakes and not waste 10 hours of their weekend because of missing quotation marks.
One of the modifications I tried over the weekend was to cat the two files in my command, but this failed :
xo-cli vm.create bootAfterCreate=true cloudConfig=$(cat /root/user.yaml) networkConfig=$(cat /root/network.yaml) clone=true name_label="Test VM" template=0856a8d6-9183-f39d-f968-290b18a1bd42 VIFs='json:[{"network":"ca96456f-3843-26f5-7075-1e54f70d8f97"}]' hvmBootFirmware=bios copyHostBiosStrings=true ā Error: invalid arg: hostname: at file:///opt/xo/xo-builds/xen-orchestra-202410090754/packages/xo-cli/index.mjs:189:13 at arrayEach (/opt/xo/xo-builds/xen-orchestra-202410090754/node_modules/lodash/_arrayEach.js:15:9) at forEach (/opt/xo/xo-builds/xen-orchestra-202410090754/node_modules/lodash/forEach.js:38:10) at parseParameters (file:///opt/xo/xo-builds/xen-orchestra-202410090754/packages/xo-cli/index.mjs:186:3) at Object.call (file:///opt/xo/xo-builds/xen-orchestra-202410090754/packages/xo-cli/index.mjs:612:18) at main (file:///opt/xo/xo-builds/xen-orchestra-202410090754/packages/xo-cli/index.mjs:437:32) at file:///opt/xo/xo-builds/xen-orchestra-202410090754/packages/xo-cli/index.mjs:668:1 at ModuleJob.run (node:internal/modules/esm/module_job:234:25) at async ModuleLoader.import (node:internal/modules/esm/loader:473:24) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
I realized just now that I completely forgot to try putting the variables in quotes, and this one simple tweak has allowed me to successfully spin up the VM with all of the correct cloud-init configurations applied
xo-cli vm.create bootAfterCreate=true cloudConfig="$(cat /root/user.yaml)" networkConfig="$(cat /root/network.yaml)" clone=true name_label="Test VM" template=0856a8d6-9183-f39d-f968-290b18a1bd42 VIFs='json:[{"network":"ca96456f-3843-26f5-7075-1e54f70d8f97"}]' hvmBootFirmware=bios copyHostBiosStrings=true 166b36b4-04a6-4dfa-b413-591dbd87195b
Thanks again for all of your help guys!