Go to file
2025-04-22 17:00:48 -04:00
bolt Restructure codebase to separate bolt plans/tasks by distro 2025-04-22 17:00:48 -04:00
hosts/vortex Notate rules for local masiero LAN traffic 2025-04-07 19:15:32 -04:00
.gitignore Update ubuntu plan for internal VMs, add availability check 2025-04-10 17:42:49 -04:00
README.md Restructure codebase to separate bolt plans/tasks by distro 2025-04-22 17:00:48 -04:00
user-data-internal.yaml Update ubuntu plan for internal VMs, add availability check 2025-04-10 17:42:49 -04:00
user-data.yaml Add bolt scripting to create VMs 2024-11-21 15:35:42 -05:00

kvm

Working on scripting to create a VM from a template.

Ubuntu 22.04.5 LTS (Jammy Jellyfish)

Note that the following steps are derived from this guide

Autoinstall configuration reference manual

Generating the autoinstall ISO

  1. Install necessary packages
apt install xorriso
apt install p7zip
  1. Download the Ubuntu image
mkdir iso-build
cd iso-build
wget https://releases.ubuntu.com/jammy/ubuntu-22.04.5-live-server-amd64.iso
  1. Unpack the files and partition the images
mkdir source-files
7z -y x ubuntu-22.04.5-live-server-amd64.iso -osource-files
  1. In the source-files directory, you will see the ISO files plus a directory named [BOOT], which contains 1-Boot-NoEmul.img and 2-Boot-NoEmul.img. Those are, respectively, the mbr (master boot record) and efi (UEFI) partition images from the ISO. They will be used to create the modified ISO. There is no reason to leave the raw image files on the new ISO, so move them out of the way and give the directory a better name.
cd source-files
ls
mv  '[BOOT]' ../BOOT
  1. Edit the grub.cfg file at source-files/boot/grub/grub.cfg
vim boot/grub/grub.cfg

Add the following above the existing menu entries:

menuentry "Autoinstall Ubuntu Server" {
    set gfxpayload=keep
    linux   /casper/vmlinuz quiet autoinstall ds=nocloud\;s=/cdrom/server/  ---
    initrd  /casper/initrd
}

This will enable autoinstall and reference the server directory where our user-data and meta-data files will be located.

  1. Create and add your custom autoinstall data files
mkdir server
cd server
touch meta-data
vim user-data

Paste the user-data.yaml content into the user-data file.

  1. Generate a new Ubuntu 22.04 server autoinstall ISO

The following command is helpful when trying to set up the arguments for building an ISO. It will give flags and data to closely reproduce the source base install ISO.

cd ../..
xorriso -indev ubuntu-22.04.5-live-server-amd64.iso -report_el_torito as_mkisofs

Using the output of the above, we create the following command. Make sure to run this from the source-files directory.

cd source-files
xorriso -as mkisofs -r \
  -V 'Ubuntu-Server 22.04.5 LTS amd64' \
  -o ../ubuntu-22.04-autoinstall.iso \
  --grub2-mbr ../BOOT/1-Boot-NoEmul.img \
  -partition_offset 16 \
  --mbr-force-bootable \
  -append_partition 2 28732ac11ff8d211ba4b00a0c93ec93b ../BOOT/2-Boot-NoEmul.img \
  -appended_part_as_gpt \
  -iso_mbr_part_type a2a0d0ebe5b9334487c068b6b72699c7 \
  -c '/boot.catalog' \
  -b '/boot/grub/i386-pc/eltorito.img' \
    -no-emul-boot -boot-load-size 4 -boot-info-table --grub2-boot-info \
  -eltorito-alt-boot \
  -e '--interval:appended_partition_2_start_1040737s_size_10072d:all::' \
  -no-emul-boot \
  .

If you want to verify the structure of the user-data file before running this or to troubleshoot later, the following can be helpful.

cloud-init schema --config-file server/user-data

Alternatively, you can also verify with:

sudo apt install yamllint
yamllint server/user-data

Once the xorriso command is run successfully, the ubuntu-22.04-autoinstall.iso will be created in the iso-build directory.

Creating the VM using Bolt

Update the parameters provided to the below plan run command as needed. Note that you should always run plans and tasks out of the bolt directory.

cd bolt
bolt plan run ubuntu::create_vm \
  target_host=vortex \
  vm_name=moeny-bank01 \
  hostname=moeny-bank01
  ip_with_cidr=100.40.223.189/24 \

Alpine VMs

There are now separate plans for generating a VM using Alpine and Ubuntu. alpine::create_vm should be run for Alpine and ubuntu::create_vm should be run for Ubuntu. These plans each run tasks tailored for the appropriate distribution.

Below is a sample command to run the Alpine bolt plan.

bolt plan run alpine::create_vm \
  vm_name=moeny-service \
  hostname=moeny-service \
  ip_with_cidr=100.40.223.189/24 \
  add_a_record_bool=true \
  dns_hostname=service

Note that add_a_record_bool must be set to true if you would like an A record for the VM to be added to the DNS server zone file, as it is false by default. If using this functionality, dns_hostname should also be provided and optionally dns_ttl if you do not want the default of 3600. The ability to interact with the DNS server depends on having set up a TSIG key on your DNS server for dynamic updates and storing a copy of your tsig.key file in a directory called keys at the root of the bolt project, alongside bolt-project.yaml. If either of these conditions have not been met, do not attempt to use this functionality. For more information on setting up dynamic DNS with a TSIG key, see our bind9 repo.

Similarly, install_docker_bool can be set to false if you do not want docker to be installed on the VM. It is true by default.

For more detailed logging on the bolt plan run add the -v flag at the end of the command.

If you want to delete an A record that you have added, you can use the delete_dns_a_record task. You'll just need to provide it with the dns_hostname you set. Here's a sample command.

bolt task run common::delete_dns_a_record dns_hostname=service --targets localhost

Lastly, even though it is designed to be run with the create_alpine plan, you can also run the add_dns_a_record task on its own. You'll just need to provide it a few parameters. Here's a sample command.

bolt task run common::add_dns_a_record add_a_record_bool=true ip_with_cidr=100.40.223.189/24 dns_hostname=service dns_ttl=3600 --targets localhost

Alternatively, to update DNS with the nsupdate command directly from the terminal, run something like the following with the path to your tsig.key:

nsupdate -k ./keys/tsig.key << EOF
server ns1.moeny.ai
debug yes
zone moeny.ai
update add service.moeny.ai 3600 A 6.5.2.5
send
EOF

ssh moeny@ns1.moeny.ai "sudo rndc sync moeny.ai"

VMs on an Internal Network

In order to spin up VMs on an internal network, you will need to generate an Alpine iso compatible with the internal IPs you are using and specify its path. You will also want to declare the staging IP and gateway IP parameters accordingly. Here is a sample command to run the Alpine bolt plan.

bolt plan run alpine::create_vm \
  vm_name=moeny-service-alpine \
  hostname=moeny-service-alpine \
  network=internal-moeny \
  ip_with_cidr=10.44.0.20/24 \
  gateway_ip=10.44.0.1 \
  iso_path=/mnt/nfs/kvm-isos/iso-build/alpine-autoinstall-internal_moeny.iso \
  staging_ip=10.44.0.250 -v

Similarly, a new Ubuntu iso will need to be generated that is compatible with the internal IPs. This can be done by simply updating the user-data file from Step 6 to have the proper network configuration, as in user-data-internal. Here is a sample command to run the Ubuntu bolt plan.

bolt plan run ubuntu::create_vm \
  vm_name=moeny-service-ubuntu \
  hostname=moeny-service-ubuntu \
  network=internal-moeny \
  ip_with_cidr=10.44.0.20/24 \
  gateway_ip=10.44.0.1 \
  iso_path=/mnt/nfs/kvm-isos/iso-build/ubuntu-22.04-autoinstall-internal_moeny.iso \
  staging_ip=internal -v