From 8f9ee3cd706df102f660c71f37ab05909d50b45d Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Fri, 28 May 2021 16:54:01 +0200 Subject: [PATCH 1/6] Trolling as a service --- zimbra/script-certificat.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/zimbra/script-certificat.sh b/zimbra/script-certificat.sh index baecf5f..d8b8b5e 100644 --- a/zimbra/script-certificat.sh +++ b/zimbra/script-certificat.sh @@ -1,2 +1,3 @@ blah blah blah d +Pas génial ce script ! From 51fda28b3e96f8df56c358477c77bbeaaa5a797b Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Fri, 18 Jun 2021 14:23:55 +0200 Subject: [PATCH 2/6] Add script to auto-create Ubuntu20 template with cloud-init in PVE --- cloud-init/create_ubuntu20_template.sh | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cloud-init/create_ubuntu20_template.sh diff --git a/cloud-init/create_ubuntu20_template.sh b/cloud-init/create_ubuntu20_template.sh new file mode 100644 index 0000000..143df47 --- /dev/null +++ b/cloud-init/create_ubuntu20_template.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +_storage=${1} +pvesm status --enabled --target localhost --content images |awk {'print $1'} |tail +2 |grep "$_storage" > /dev/null 2>&1 +if [ "$?" -ne "0" ]; then + echo "Storage $_storage does not seems to exists. Use 'pvesm status' to find a usable storage" + exit 1 +fi + +/usr/sbin/qm status 9999 > /dev/null 2>&1 +if [ "$?" -ne "2" ]; then + echo "VM9999 already exists, aborting" + exit 1 +fi + +echo "Storage $_storage is valid and VM does not exists, let's get the latest Ubuntu-minimal image from repo" + +# Récupération de l'image Ubuntu +#curl --progress-bar -o ubuntu-20.04-minimal-cloudimg-amd64.img https://cloud-images.ubuntu.com/minimal/releases/focal/release/ubuntu-20.04-minimal-cloudimg-amd64.img + +# Silently download public SSH key +curl -s -o support@altinea.fr.pub https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/support@altinea.fr.pub + +/usr/sbin/qm create 9999 --memory 1024 --net0 virtio,bridge=vmbr0 +/usr/sbin/qm importdisk 9999 ubuntu-20.04-minimal-cloudimg-amd64.img $_storage +/usr/sbin/qm set 9999 --scsihw virtio-scsi-pci --scsi0 $_storage:vm-9999-disk-0,discard=on +/usr/sbin/qm set 9999 --ide2 $_storage:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0 +/usr/sbin/qm template 9999 +/usr/sbin/qm set 9999 --args "-cpu 'kvm64,+ssse3,+sse4.1,+sse4.2,+x2apic'" --ciuser root --ipconfig0 ip=dhcp,ip6=dhcp --sshkeys support@altinea.fr.pub --name "Ubuntu20.04" --agent enabled=1 + +echo "All done, you can now clone VM9999 (Ubuntu20.04) from PVE interface" From c6ac06434aded112d04d2946cdfe8ae69a325fb3 Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Fri, 18 Jun 2021 14:33:25 +0200 Subject: [PATCH 3/6] Re-enable image download, delete temporary files and (basic) test args --- cloud-init/create_ubuntu20_template.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cloud-init/create_ubuntu20_template.sh b/cloud-init/create_ubuntu20_template.sh index 143df47..2fc3f29 100644 --- a/cloud-init/create_ubuntu20_template.sh +++ b/cloud-init/create_ubuntu20_template.sh @@ -15,17 +15,26 @@ fi echo "Storage $_storage is valid and VM does not exists, let's get the latest Ubuntu-minimal image from repo" -# Récupération de l'image Ubuntu -#curl --progress-bar -o ubuntu-20.04-minimal-cloudimg-amd64.img https://cloud-images.ubuntu.com/minimal/releases/focal/release/ubuntu-20.04-minimal-cloudimg-amd64.img +# Fetching the last Ubuntu Minimal 20.04 cloud-image +curl --progress-bar -o ubuntu-20.04-minimal-cloudimg-amd64.img https://cloud-images.ubuntu.com/minimal/releases/focal/release/ubuntu-20.04-minimal-cloudimg-amd64.img # Silently download public SSH key curl -s -o support@altinea.fr.pub https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/support@altinea.fr.pub +# Create VM, import cloud-image and configure storage /usr/sbin/qm create 9999 --memory 1024 --net0 virtio,bridge=vmbr0 /usr/sbin/qm importdisk 9999 ubuntu-20.04-minimal-cloudimg-amd64.img $_storage /usr/sbin/qm set 9999 --scsihw virtio-scsi-pci --scsi0 $_storage:vm-9999-disk-0,discard=on /usr/sbin/qm set 9999 --ide2 $_storage:cloudinit --boot c --bootdisk scsi0 --serial0 socket --vga serial0 + +# Convert VM to template /usr/sbin/qm template 9999 + +# Adjust VM settings (based on best practices) /usr/sbin/qm set 9999 --args "-cpu 'kvm64,+ssse3,+sse4.1,+sse4.2,+x2apic'" --ciuser root --ipconfig0 ip=dhcp,ip6=dhcp --sshkeys support@altinea.fr.pub --name "Ubuntu20.04" --agent enabled=1 +# Delete temporary files +rm ubuntu-20.04-minimal-cloudimg-amd64.img +rm support@altinea.fr.pub + echo "All done, you can now clone VM9999 (Ubuntu20.04) from PVE interface" From 67b12d12f658f5b3fecd89775fa4d120614c819a Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Fri, 18 Jun 2021 14:41:46 +0200 Subject: [PATCH 4/6] Verify args --- cloud-init/create_ubuntu20_template.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cloud-init/create_ubuntu20_template.sh b/cloud-init/create_ubuntu20_template.sh index 2fc3f29..ff154b1 100644 --- a/cloud-init/create_ubuntu20_template.sh +++ b/cloud-init/create_ubuntu20_template.sh @@ -1,6 +1,15 @@ #!/bin/sh -_storage=${1} +_usage() { + echo " + Usage: $0 + : should be a valid (active, supporting VM image) PVE storage + " +} + +[ -z "$1" ] && _usage && return + +_storage=$1 pvesm status --enabled --target localhost --content images |awk {'print $1'} |tail +2 |grep "$_storage" > /dev/null 2>&1 if [ "$?" -ne "0" ]; then echo "Storage $_storage does not seems to exists. Use 'pvesm status' to find a usable storage" From 40b4c34a9862e446c87554032a6ee656d87b7c22 Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Fri, 18 Jun 2021 14:55:07 +0200 Subject: [PATCH 5/6] Small readme with usage --- cloud-init/Readme.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 cloud-init/Readme.md diff --git a/cloud-init/Readme.md b/cloud-init/Readme.md new file mode 100644 index 0000000..c4f16e9 --- /dev/null +++ b/cloud-init/Readme.md @@ -0,0 +1,4 @@ +Create an Ubuntu 20.04 template on a PVE server : +``` +curl -Ls https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/cloud-init/create_ubuntu20_template.sh |sh -s -- +``` From 1b4ceb41d7751203c33c740774d0dd50f4602e14 Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Fri, 18 Jun 2021 15:15:35 +0200 Subject: [PATCH 6/6] Update readme --- cloud-init/Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cloud-init/Readme.md b/cloud-init/Readme.md index c4f16e9..50aca93 100644 --- a/cloud-init/Readme.md +++ b/cloud-init/Readme.md @@ -2,3 +2,4 @@ Create an Ubuntu 20.04 template on a PVE server : ``` curl -Ls https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/cloud-init/create_ubuntu20_template.sh |sh -s -- ``` +\ should be a valid declared storage accessible on the PVE server