post-process.sh (1096B)
1 #!/usr/bin/env bash 2 3 set -o errexit 4 set -o nounset 5 #set -o xtrace 6 7 # https://pve.proxmox.com/wiki/Proxmox_VE_API 8 # https://pve.proxmox.com/wiki/Cloud-Init_Support#_preparing_cloud_init_templates 9 10 yum install -y epel-release jq curl 11 12 # read vm id from latest build 13 vmid=$(jq -r '.builds | sort_by(.build_time) | reverse | .[0].artifact_id' "$PACKER_MANIFEST") 14 15 # pve api authorization 16 ticket=$(curl -s -d "username=$PM_USER&password=$PM_PASS" "$PM_API_URL/access/ticket") 17 cookie=$(echo "$ticket" | jq -r ".data.ticket" | sed "s/^/PVEAuthCookie=/") 18 csrftoken=$(echo "$ticket" | jq -r '.data.CSRFPreventionToken' | sed 's/^/CSRFPreventionToken:/') 19 20 # add cloud-init drive 21 curl -s -H "$csrftoken" -XPOST -b "$cookie" \ 22 "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" \ 23 --data-urlencode cdrom="local-lvm:cloudinit" 24 25 # 26 # show cloud-init drive 27 #curl -s -XGET -b "$cookie" \ 28 # "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" | jq '.data.cdrom' 29 # 30 # delete cloud-init drive 31 #curl -s -H "$csrftoken" -XPOST -b "$cookie" \ 32 # "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" \ 33 # --data-urlencode delete="cdrom"