Skip to content

Instantly share code, notes, and snippets.

@ravnoor
Forked from nkabir/01-netcfg.yaml
Created September 22, 2023 18:55
Show Gist options
  • Select an option

  • Save ravnoor/b17cf53e4d8fc66e5d38979b80143e53 to your computer and use it in GitHub Desktop.

Select an option

Save ravnoor/b17cf53e4d8fc66e5d38979b80143e53 to your computer and use it in GitHub Desktop.
libguestfs examples
# may be templated in the future
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: true
optional: true
#!/usr/bin/env bash
set -o errexit
set -o pipefail
readonly CODENAME="{{ os_version }}"
# image file name
readonly IMG_FR="${CODENAME:?}-server-cloudimg-amd64.img"
# cloud image uri
readonly IMG_URI=https://cloud-images.ubuntu.com/${CODENAME:?}/current/${IMG_FR:?}
# absolute path to cloud image file
readonly IMG_FA="${KVM_IMAGE_DA:?}/${IMG_FR:?}"
# absolute path to virtbuilder file
readonly VB_FA="${KVM_IMAGE_DA:?}/${VIRTBUILDER_NAME:?}.${KVM_IMAGE_FORMAT:?}"
# does img file exist?
[[ -e "${IMG_FA:?}" ]] || {
curl "${IMG_URI:?}" -o "${IMG_FA:?}"
}
# copy downloaded cloud img to qcow2
cp "${IMG_FA:?}" "${VB_FA:?}"
# bug in cloud image
# https://bugs.launchpad.net/cloud-images/+bug/1573095
# generates <name>-vb.qcow2
virt-customize \
--format "${KVM_IMAGE_FORMAT:?}" \
--no-network \
--hostname "${VIRTBUILDER_NAME:?}" \
--ssh-inject "root:file:$HOME/.ssh/id_rsa.pub" \
--copy-in build/01-netcfg.yaml:/etc/netplan \
--root-password "file:$HOME/.ssh/kvm.password" \
--run-command "sed -i 's/ console=ttyS0//g' /etc/default/grub.d/50-cloudimg-settings.cfg" \
--run-command "sed -i 's/GRUB_CMDLINE_LINUX/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0 console=tty1\"/g' /etc/default/grub" \
--run-command "update-grub" \
--run-command "sed -i 's/ibm-p8-kvm-03-guest-02.virt.pnr.lab.eng.rdu2.redhat.com//g' /etc/hosts" \
--run-command "systemctl mask apt-daily.service apt-daily-upgrade.service" \
--firstboot-command "netplan generate && netplan apply" \
--firstboot-command "dpkg-reconfigure openssh-server" \
--firstboot-command "sync" \
-a "${VB_FA:?}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment