Ubuntu 22 Cloud Init/Config Network & Partition Assistance
-
Good day
Hope everyone is well
I have begun to look into using Cloud Config to make it a simpler process to push out new VMs
This is for Ubuntu 22.04, the only variables I'd want to input would be the hostname, a static IP, disk space and install specified packages
So far I managed to get the config template to install the VM with the custom hostname
I still have trouble getting the network config working and having the new VM make use of the entire assigned disk space. The new VM will only use the original template VM's disk space (10GBs) and not extend the volume with entered disk space valueMy current network template:
#network: version: 1 config: - type: physical name: eth0 subnets: type: static address: 129.232.201.212/26 gateway: 129.232.201.193 dns_nameservers: - 8.8.8.8 - 1.1.1.1
Current user config
#cloud-config hostname: TEST growpart: mode: 'on' resize_rootfs: true package_update: true packages: - htop - whois
My process for creating the template:
- Install Ubuntu 22.04
- Install Guest tools
- apt update && sudo apt upgrade
- Reboot
- apt purge cloud-init cloud-initramfs-dyn-netconf cloud-initramfs-copymods -y
- rm -rf /etc/cloud/; rm -rf /var/lib/cloud/
- apt update && apt full-upgrade -y
- apt install cloud-initramfs-dyn-netconf cloud-initramfs-copymods cloud-initramfs-growroot -y
- cloud-init clean
Remove/Clear the following:
10.a rm /etc/cloud/cloud.cfg.d/99-installer.cfg
10.b rm /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg
10.c rm /etc/netplan/00-installer-config.yaml
10.d rm -rf /tmp/* && rm -rf /var/tmp/*
10.e rm -f /etc/ssh/ssh_host_*
10.f truncate -s 0 /etc/hostname && truncate -s 0 /etc/machine-id-
Edit cloud.cfg
Here I only commented out the default users, as the users I set won't need to change -
apt autoremove && apt clean
-
cloud-init clean && cloud-init clean --logs
Shutdown and convert to template
I believe my error is the disk and network are not defined in cloud.cfg
Would anyone be able to assist with examples or suggest how to correctly define the volumes and network interface
I will happy to provide any additional information or logs
Thank you
-
My cloud-inits are below, I don't mess around with building my own templates and just download the pre-made Ubuntu ones: https://cloud-images.ubuntu.com/jammy/
#cloud-config hostname: {name} timezone: America/New_York users: - default - name: netserv passwd: passwordhash ssh_import_id: - gh:guthub_account sudo: ALL=(ALL) NOPASSWD:ALL groups: users, admin, sudo shell: /bin/bash lock_passwd: true ssh_authorized_keys: - ssh-ed25519 yourkey package_update: true packages: - xe-guest-utilities package_upgrade: true runcmd: - sudo reboot
And network, though this is no longer the correct way to handle it, I've yet to update
version: 2 ethernets: eth0: dhcp4: false dhcp6: false addresses: - 172.16.100.185/24 gateway4: 172.16.100.1 nameservers: addresses: - 172.16.100.21 - 172.16.100.22 - 1.1.1.1 search: - dev.themaw.tech
-
@gsrfan01
Hi there!Thank you for taking the time to reply, I will try out your example inits
I initially went with setting up my own template since I have several golden disks to use
So you only use those above inits and don't modify cloud.cfg at all?
I appreciate the help!
-
No modifications at all. I download the OVA, import into Xen Orchestra, usually change the cpu to 2 cores and ram to 2gb, then convert to template.
I select the template and the cloud configs when creating a new VM. It expands the file system, sets up the user, imports SSH keys, updates packages, installs the tools, then reboots.
You can expand it to add addition users, keys, packages, etc.
-
@gsrfan01 I have taken up XCP-NG for setting up home lab (K8s), and would take your suggestions in creating the template. I would post any issues encountered here to bring up VM instances. thanks
-
@gsrfan01
Good day GsrfanI have managed to get the network going using your example network init, thank you it helped a bunch!
So far I can't access the test VM, the default ubuntu user and my custom user don't accept the credentials.
I have seen online it's possible to define the ssh keys in the init, is it a simple enough alternative to Github?Thank you
-
@Lulina I was trying to have the cloud config and network saved but got error with redis. I couldn't progress further. Do you have the template for those configs.
-
@rajudm
Hi thereWe just need some more info from your side
What error did you get?
Which distro are you using to deploy the VMs? -
@Lulina using cloud image from ubuntu 22.04 --> ubuntu-22.04-server-cloudimg-amd64.ova
While creating config's i get errors
what would be the ideal cloud config and network config for the following.
Cloud config
Name
Template
#cloud-config
#hostname: {name}%
#ssh_authorized_keys:- ssh-rsa <myKey>
#packages:
- htop
0 items
ID Name
No items found
Network config
Name
TemplateWith the same image got the VM template created and VM created in proxmox following Jay Linux's video. A similar one is required for XCP-NG to make popular in community edition. I was looking at exporting from Proxmox and Importing into XCP-NG. Not sure if that would work either given the networking variability among hypervisors.
-
If you don't want to import Github keys at all, you can remove that portion and specify it under
ssh_authorized_keys
for each user built from cloud-init.#cloud-config hostname: {name} timezone: America/New_York users: - default - name: YOURUSER passwd: YOURPASSWORDHASH sudo: ALL=(ALL) NOPASSWD:ALL groups: users, admin, sudo shell: /bin/bash lock_passwd: true ssh_authorized_keys: - ssh-rsa YOURKEY package_update: true packages: - xe-guest-utilities - htop package_upgrade: true
If you want to be able to log in from the console instead of only SSH using keys, change
lock_passwd: true
tolock_passwd: false
-
Hi there Gsrfan
Apologies for the delayed response, I had to shelf this passion project to focus on other work
So far managed to get the host, static IP, packages, users & their keys/password etc sorted with the initI was working last on lvm partitions, to grow them and that ended up a bit of a mess
I might return to this at a later stage but I found your help and advice invaluable to getting the config to where it is now
Thank you so much