Cloud-init success
-
I thought I would share some success with cloud-init. I know it has been a pain for others to get working. Please disregard if this is old news.
Just for fun, I wanted to see if I could just use the stock/prebuilt Ubuntu 22.04-LTS cloud ready images I have used in production. Almost like magic it worked fantastic. I expected hours of pain and debugging like others have had to suffer. However to it took me about 2 minutes to spin up a fully configured Ubuntu VM with all my PKI keys, users, updates, packages, configs, etc.
So here is what I did, just in case this is helpful for any other noobies like myself getting acquainted with XO and using cloud-init.
So I used the prebuilt cloud image for Ubuntu found here: https://cloud-images.ubuntu.com/jammy/current/
Step 1:
I selected the "jammy-server-cloudimg-amd64.ova" stock file for vmware/virtual box and downloaded.Step 2:
Then in XO, I imported the file as a VM - import - VM.Step 3:
Then I went into settings, and created a new cloud config with my usual user, ssh, packages, and other custom settings as I normally use in the lab for testing prior to rolling into production. I just copy/pasted my full config, and saved it.Step 4:
Then I converted the cloud image VM I imported in step 2 into a template.Step 5:
Then I created a fresh VM, using this new template, making sure to select my cloud-init config by checking the "Custom config" selection under Install settings.Step 6:
Then I opened the console to watch for FAIL errors. Everything looked good. Then I logged in with my ansible account configured in the cloud-init. Then I tested from my ansible control node, and logged in. I inspected /var/log/cloud-init.log for any errors, and finally I ran "cloud-init query userdata" to see how it rendered the config settings. Everything works as it should.Next I will try the cloud-init config with jinja2 template directives and see if the jinja engine works as well, so I can use one config for all distros I will be using. Then test network config settings. Then test on Centos, Rocky, RHEL cloud-ready images and report back if I run into any snags on those.
-
@dj423 Thanks for sharing. Would you mind adding the config file you used ? thanks!
-
Sure, I have several configs in production depending on the use-case/role for the node.
Here is a sanitized version of one of the more basic configs for Ubuntu images for reference:
#cloud-config hostname: {name}% users: ## Add users - name: user1 groups: sudo lock_passwd: false passwd: $6$xxxx....... ssh_authorized_keys: - ssh-ed25519 <my-key-ed25519> shell: /bin/bash ## Add ansible acct & key - name: ansible groups: sudo lock_passwd: false passwd: $6$xxxxxx736363535353.8ahdVT625S/ ssh_authorized_keys: - ssh-ed25519 <somekey> shell: /bin/bash package_update: true package_upgrade: true packages: - build-essential - htop - nano - nfs-common - git locale: en_US.UTF-8 timezone: America/New_York runcmd: - mkdir /mnt/v-nas - date > /etc/birth_certificate - mount /dev/cdrom /mnt - bash /mnt/Linux/install.sh - umount /dev/cdrom
Just add your pw hashes and key strings and tweak what you need for your config. This one is pretty basic so it runs through fairly quick and loads the xen-tools.
I have a very large "universal" one for Debian, Redhat, Centos, Rocky, Ubuntu with jinja templating and all the snazzy features I can sanitize and share if you like that I use for both VM's and containers.
-
@dj423 thank you, that is really helpful!
I also found : https://cloudinit.readthedocs.io/en/latest/reference/examples.htmlSome things are mentioned here :
https://xcp-ng.org/forum/topic/7177/cloud-config-success
that you did not seem to need ? I will try it out.I saw the Kubernetes recipe uses cloud config files and I am interested to use it for an OKD installation.
I really like XCP-ng so far, cheers! -
@VGerris said in Cloud-init success:
@dj423 thank you, that is really helpful!
I also found : https://cloudinit.readthedocs.io/en/latest/reference/examples.htmlYes the docs are a huge help when crafting big nuanced config scripts. The lead maintainer Chad Smith gave me some pro-tips as well and was a huge help for me when I was learning that stuff. Yes I agree, Xcp-ng rocks!!
Best of luck!
-