Creating an Ubuntu 20.04 cloud template & cloud-init configuration in Xen Orchestra

/ Documentation / How-To / Networking

I had a need in my home lab to quickly deploy a bunch of thin clones of Ubuntu’s cloud image. I chose to use the cloud images Ubuntu provides instead of building a custom template.

Xen Orchestra has had support for cloud-init since 2015.

Quick Walkthrough

Here is the short version of how this works:

  1. Download the current 20.04 ubuntu cloud image OVA file, there should only be 1 on each build’s page. I used focal-server-cloudimg-amd64.ova
  2. In Xen Orchestra, Import -> VM, then drag & drop your ova onto the obvious place. Set the default CPU, Memory, and target VM Network settings & click Import
  3. When it’s finished, you can click on Home -> VMs, and clear the “power_state:running” filter from the display.
  4. Select the powered-off vm, and rename it whatever you want.
  5. On the Advanced tab, click “Convert to template”
  6. Click the “New VM” button in the top-right corner
  7. Choose a pool
  8. Select your newly-created template from the list
  9. Adjust CPU, Ram, etc as necessary.
  10. Under the “Install settings” header, choose a custom config
  11. Paste your customized User and Network config
  12. Click “Create”

Example cloud-init configs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#cloud-config
hostname: {name}
users:
  - name: jappleseed
    gecos: jappleseed
    primary_group: jappleseed
    groups: adm
    lock_passwd: false
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
    ssh_authorized_keys:
      - ssh-rsa KEYCONTENTS user@HOSTNAME

ca-certs:
  trusted: 
  - |
    -----BEGIN CERTIFICATE-----
    # The indented contents of your CA cert go here:
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
    -----END CERTIFICATE-----

Network config

I don’t know if this is unique to Xen Orchestra or not, but the syntax of the network config is a little odd. No matter what else you change, leave the first line EXACTLY as you see it below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            addresses:
                - 192.168.0.124/24
                - 2001:db8::1:9f/64
            gateway4: 192.168.0.1
            nameservers:
                search: [example.com]
                addresses: [192.168.0.1, 8.8.8.8]

Caveats

This approach is fast, but doesn’t properly install the xcp-ng guest tools. You’ll probably want those if you want XCP-NG or Xen-Orchestra to be able to dive into each guest VM and display a useful level of detail about the guest. You can do a normal install from an iso, install some packages and run “cloud-init clean”, then immediately shut down the VM. This will force cloud init to run the same way it would if this were a fresh machine - generating host keys, naming the machine and applying any other config you pass in.

Photo of Aaron Glenn
Aaron Glenn Admin/Mentor

Aaron is a Sr. Systems Administrator from Tulsa, specializing in Microsoft technologies, with an emphasis on powershell.