Skip to content

Instantly share code, notes, and snippets.

@seanb4t
Forked from chriswayg/create-cloud-template.sh
Last active May 25, 2021 00:12
Show Gist options
  • Save seanb4t/8ac6908bb89bc68c7011b4417e8cca83 to your computer and use it in GitHub Desktop.
Save seanb4t/8ac6908bb89bc68c7011b4417e8cca83 to your computer and use it in GitHub Desktop.

Revisions

  1. seanb4t revised this gist May 25, 2021. No changes.
  2. seanb4t revised this gist May 23, 2021. No changes.
  3. seanb4t revised this gist May 23, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -191,8 +191,8 @@ qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-d
    printf "\n** Setting boot\n"
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0

    # printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    # qm set $VMID --ipconfig0 ip=dhcp
    printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    qm set $VMID --ipconfig0 ip=dhcp
    #This would work in a bridged setup, but a routed setup requires a route to be added in the guest
    #qm set $VMID --ipconfig0 ip=10.10.10.222/24,gw=10.10.10.1

  4. seanb4t revised this gist May 23, 2021. No changes.
  5. seanb4t revised this gist May 23, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -191,8 +191,8 @@ qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-d
    printf "\n** Setting boot\n"
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0

    printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    qm set $VMID --ipconfig0 ip=dhcp
    # printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    # qm set $VMID --ipconfig0 ip=dhcp
    #This would work in a bridged setup, but a routed setup requires a route to be added in the guest
    #qm set $VMID --ipconfig0 ip=10.10.10.222/24,gw=10.10.10.1

  6. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -189,7 +189,7 @@ printf "\n** Attaching the disk to the vm using VirtIO SCSI\n"
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-disk-0.qcow2

    printf "\n** Setting boot\n"
    qm set $VMID --boot c --bootdisk scsi0 #--serial0 socket --vga serial0
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0

    printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    qm set $VMID --ipconfig0 ip=dhcp
  7. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -189,7 +189,7 @@ printf "\n** Attaching the disk to the vm using VirtIO SCSI\n"
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-disk-0.qcow2

    printf "\n** Setting boot\n"
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0
    qm set $VMID --boot c --bootdisk scsi0 #--serial0 socket --vga serial0

    printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    qm set $VMID --ipconfig0 ip=dhcp
  8. seanb4t revised this gist May 23, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -188,8 +188,8 @@ qm importdisk $VMID /tmp/$VMIMAGE nas-cluster-store -format qcow2
    printf "\n** Attaching the disk to the vm using VirtIO SCSI\n"
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-disk-0.qcow2

    # printf "\n** Setting boot and display settings with serial console\n"
    # qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0
    printf "\n** Setting boot\n"
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0

    printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    qm set $VMID --ipconfig0 ip=dhcp
  9. seanb4t revised this gist May 23, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -188,8 +188,8 @@ qm importdisk $VMID /tmp/$VMIMAGE nas-cluster-store -format qcow2
    printf "\n** Attaching the disk to the vm using VirtIO SCSI\n"
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-disk-0.qcow2

    printf "\n** Setting boot and display settings with serial console\n"
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0
    # printf "\n** Setting boot and display settings with serial console\n"
    # qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0

    printf "\n** Using a dhcp server on $BRIDGE (or change to static IP)\n"
    qm set $VMID --ipconfig0 ip=dhcp
  10. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -214,7 +214,7 @@ then
    printf "\n** Adding user configuration\n"
    cp -v $PWD/$USERCONFIG $SNIPPETSPATH/$VMID-$OSNAME-$USERCONFIG
    qm set $VMID --cicustom "user=nas-cluster-store:snippets/$VMID-$OSNAME-$USERCONFIG"
    printf "#* cloud-config: $VMID-$OSNAME-$USERCONFIG\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    printf "#* cloud-config: $VMID-$OSNAME-$USERCONFIG\n" >> /etc/pve/nodes/$(hostname)/qemu-server/$VMID.conf
    else
    # The SSH key should be supplied either in the cloud-init config file or here
    printf "\n** Skipping config file, as none was found\n\n** Adding SSH key\n"
  11. seanb4t revised this gist May 23, 2021. No changes.
  12. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -47,7 +47,7 @@ read -p "* Enter number of distro to use: " OSNR
    RESIZE=+30G
    MEMORY=2048
    BRIDGE=vmbr0
    USERCONFIG_DEFAULT=none # cloud-init-config.yml
    USERCONFIG_DEFAULT=cloud-init-config.yml # cloud-init-config.yml
    CITYPE=nocloud
    SNIPPETSPATH=/mnt/pve/nas-cluster-store/snippets
    SSHKEY=~/.ssh/sean.pub # ~/.ssh/id_rsa.pub
  13. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ MEMORY=2048
    BRIDGE=vmbr0
    USERCONFIG_DEFAULT=none # cloud-init-config.yml
    CITYPE=nocloud
    SNIPPETSPATH=/mnt/pve/nas-cluster-store/snippets/
    SNIPPETSPATH=/mnt/pve/nas-cluster-store/snippets
    SSHKEY=~/.ssh/sean.pub # ~/.ssh/id_rsa.pub
    NOTE=""

  14. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ MEMORY=2048
    BRIDGE=vmbr0
    USERCONFIG_DEFAULT=none # cloud-init-config.yml
    CITYPE=nocloud
    SNIPPETSPATH=/var/lib/vz/snippets
    SNIPPETSPATH=/mnt/pve/nas-cluster-store/snippets/
    SSHKEY=~/.ssh/sean.pub # ~/.ssh/id_rsa.pub
    NOTE=""

  15. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -213,7 +213,7 @@ then
    # The cloud-init user config file overrides the user settings done elsewhere
    printf "\n** Adding user configuration\n"
    cp -v $PWD/$USERCONFIG $SNIPPETSPATH/$VMID-$OSNAME-$USERCONFIG
    qm set $VMID --cicustom "user=local:snippets/$VMID-$OSNAME-$USERCONFIG"
    qm set $VMID --cicustom "user=nas-cluster-store:snippets/$VMID-$OSNAME-$USERCONFIG"
    printf "#* cloud-config: $VMID-$OSNAME-$USERCONFIG\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    else
    # The SSH key should be supplied either in the cloud-init config file or here
  16. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -225,7 +225,7 @@ else
    && printf "\n** Adding the password to the config\n" \
    && qm set $VMID --cipassword $PASSWORD \
    && printf "#* a password has been set for the default user\n" >> /etc/pve/nodes/$(hostname)/qemu-server/$VMID.conf
    printf "#- cloud-config used: via Proxmox\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    printf "#- cloud-config used: via Proxmox\n" >> /etc/pve/nodes/$(hostname)/qemu-server/$VMID.conf
    fi

    # The NOTE is added to the Summary section of the VM (TODO there seems to be no 'qm' command for this)
  17. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -229,7 +229,7 @@ else
    fi

    # The NOTE is added to the Summary section of the VM (TODO there seems to be no 'qm' command for this)
    printf "#$NOTE\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    printf "#$NOTE\n" >> /etc/pve/nodes/$(hostname)/qemu-server/$VMID.conf

    printf "\n** Increasing the disk size\n"
    qm resize $VMID scsi0 $RESIZE
  18. seanb4t revised this gist May 23, 2021. No changes.
  19. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -224,7 +224,7 @@ else
    [ ! -z "$PASSWORD" ] \
    && printf "\n** Adding the password to the config\n" \
    && qm set $VMID --cipassword $PASSWORD \
    && printf "#* a password has been set for the default user\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    && printf "#* a password has been set for the default user\n" >> /etc/pve/nodes/$(hostname)/qemu-server/$VMID.conf
    printf "#- cloud-config used: via Proxmox\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    fi

  20. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -202,7 +202,7 @@ qm set $VMID --ide2 nas-cluster-store:cloudinit
    printf "\n** Specifying the cloud-init configuration format\n"
    qm set $VMID --citype $CITYPE

    printf "#** Made with create-cloud-template.sh - https://gist.github.com/seanb4t/8ac6908bb89bc68c7011b4417e8cca83\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    printf "#** Made with create-cloud-template.sh - https://gist.github.com/seanb4t/8ac6908bb89bc68c7011b4417e8cca83\n" >> /etc/pve/nodes/$(hostname)/qemu-server/$VMID.conf

    ## TODO: Also ask for a network configuration. Or create a config with routing for a static IP
    printf "\n*** The script can add a cloud-init configuration with users and SSH keys from a file in the current directory.\n"
  21. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -85,7 +85,7 @@ case $OSNR in
    VMIMAGE=hirsute-server-cloudimg-amd64.img
    NOTE="\n## Default user is 'ubuntu'\n"
    printf "$NOTE\n"
    wget -P /tmp -N https://cloud-images.ubuntu.com/bionic/current/$VMIMAGE
    wget -P /tmp -N https://cloud-images.ubuntu.com/hirsute/current/$VMIMAGE
    ;;

    5)
  22. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ printf "\n*** This script will download a cloud image and create a Proxmox VM te
    ## TODO
    ## - verify authenticity of downloaded images using hash or GPG

    printf "* Available templates to generate:\n 2) Debian 9\n 3) Debian 10\n 4) Ubuntu 18.04\n 5) Centos 7\n 6) CoreOS/Flatcar\n 7) Arch\n 8) Alpine 3.11\n 9) RancherOS 1.5.5\n\n"
    printf "* Available templates to generate:\n 2) Debian 9\n 3) Debian 10\n 4) Ubuntu 21.04\n 5) Centos 7\n 6) CoreOS/Flatcar\n 7) Arch\n 8) Alpine 3.11\n 9) RancherOS 1.5.5\n\n"
    read -p "* Enter number of distro to use: " OSNR

    # defaults which are used for most templates
  23. seanb4t revised this gist May 23, 2021. No changes.
  24. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -202,7 +202,7 @@ qm set $VMID --ide2 nas-cluster-store:cloudinit
    printf "\n** Specifying the cloud-init configuration format\n"
    qm set $VMID --citype $CITYPE

    printf "#** Made with create-cloud-template.sh - https://gist.github.com/chriswayg/43fbea910e024cbe608d7dcb12cb8466\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf
    printf "#** Made with create-cloud-template.sh - https://gist.github.com/seanb4t/8ac6908bb89bc68c7011b4417e8cca83\n" >> /etc/pve/nodes/proxmox/qemu-server/$VMID.conf

    ## TODO: Also ask for a network configuration. Or create a config with routing for a static IP
    printf "\n*** The script can add a cloud-init configuration with users and SSH keys from a file in the current directory.\n"
  25. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -186,7 +186,7 @@ printf "\n** Importing the disk in qcow2 format (as 'Unused Disk 0')\n"
    qm importdisk $VMID /tmp/$VMIMAGE nas-cluster-store -format qcow2

    printf "\n** Attaching the disk to the vm using VirtIO SCSI\n"
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 /var/lib/vz/images/$VMID/vm-$VMID-disk-0.qcow2
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 nas-cluster-store:$VMID/vm-$VMID-disk-0.qcow2

    printf "\n** Setting boot and display settings with serial console\n"
    qm set $VMID --boot c --bootdisk scsi0 --serial0 socket --vga serial0
  26. seanb4t revised this gist May 23, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ case $OSNR in
    VMID_DEFAULT=52000
    read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID
    VMID=${VMID:-$VMID_DEFAULT}
    VMIMAGE=bionic-server-cloudimg-amd64.img
    VMIMAGE=hirsute-server-cloudimg-amd64.img
    NOTE="\n## Default user is 'ubuntu'\n"
    printf "$NOTE\n"
    wget -P /tmp -N https://cloud-images.ubuntu.com/bionic/current/$VMIMAGE
    @@ -183,7 +183,7 @@ printf "\n** Creating a VM with $MEMORY MB using network bridge $BRIDGE\n"
    qm create $VMID --name $OSNAME-cloud --memory $MEMORY --net0 virtio,bridge=$BRIDGE

    printf "\n** Importing the disk in qcow2 format (as 'Unused Disk 0')\n"
    qm importdisk $VMID /tmp/$VMIMAGE local -format qcow2
    qm importdisk $VMID /tmp/$VMIMAGE nas-cluster-store -format qcow2

    printf "\n** Attaching the disk to the vm using VirtIO SCSI\n"
    qm set $VMID --scsihw virtio-scsi-pci --scsi0 /var/lib/vz/images/$VMID/vm-$VMID-disk-0.qcow2
    @@ -197,7 +197,7 @@ qm set $VMID --ipconfig0 ip=dhcp
    #qm set $VMID --ipconfig0 ip=10.10.10.222/24,gw=10.10.10.1

    printf "\n** Creating a cloudinit drive managed by Proxmox\n"
    qm set $VMID --ide2 local:cloudinit
    qm set $VMID --ide2 nas-cluster-store:cloudinit

    printf "\n** Specifying the cloud-init configuration format\n"
    qm set $VMID --citype $CITYPE
  27. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -78,7 +78,7 @@ case $OSNR in
    ;;

    4)
    OSNAME=ubuntu1804
    OSNAME=ubuntu2104
    VMID_DEFAULT=52000
    read -p "Enter a VM ID for $OSNAME [$VMID_DEFAULT]: " VMID
    VMID=${VMID:-$VMID_DEFAULT}
  28. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ BRIDGE=vmbr0
    USERCONFIG_DEFAULT=none # cloud-init-config.yml
    CITYPE=nocloud
    SNIPPETSPATH=/var/lib/vz/snippets
    SSHKEY=~/.ssh/2019_id_rsa.pub # ~/.ssh/id_rsa.pub
    SSHKEY=~/.ssh/sean.pub # ~/.ssh/id_rsa.pub
    NOTE=""

    case $OSNR in
  29. seanb4t revised this gist May 23, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion create-cloud-template.sh
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ read -p "* Enter number of distro to use: " OSNR
    # defaults which are used for most templates
    RESIZE=+30G
    MEMORY=2048
    BRIDGE=vmbr1
    BRIDGE=vmbr0
    USERCONFIG_DEFAULT=none # cloud-init-config.yml
    CITYPE=nocloud
    SNIPPETSPATH=/var/lib/vz/snippets
  30. seanb4t revised this gist May 23, 2021. No changes.