packer-builds

Packer Builds for LXC and Libvirt
git clone https://git.in0rdr.ch/packer-builds.git
Log | Files | Refs | README

commit a1bfd113e04af2af3af5590b71d12b650356f80b
Author: Andreas Gruhler <andreas.gruhler@adfinis-sygroup.ch>
Date:   Sat, 21 Dec 2019 01:19:17 +0000

init

Diffstat:
Acentos8.json | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aconfig/centos8-ks.cfg | 36++++++++++++++++++++++++++++++++++++
Ascripts/cloud-config.sh | 17+++++++++++++++++
Ascripts/post-process.sh | 33+++++++++++++++++++++++++++++++++
4 files changed, 163 insertions(+), 0 deletions(-)

diff --git a/centos8.json b/centos8.json @@ -0,0 +1,77 @@ +{ + "variables": { + "username": "{{env `PM_USER`}}", + "password": "{{env `PM_PASS`}}", + "api_url": "{{env `PM_API_URL`}}", + "pve_node": "{{env `PM_NODE`}}", + "pve_pool": "{{env `PM_POOL`}}", + "manifest": "manifest.json" + }, + "sensitive-variables": ["password"], + "builders": [ + { + "type": "proxmox", + "proxmox_url": "{{user `api_url`}}", + "username": "{{user `username`}}", + "password": "{{user `password`}}", + "node": "{{user `pve_node`}}", + "pool": "{{user `pve_pool`}}", + "network_adapters": [ + { + "bridge": "vmbr0", + "model": "virtio" + } + ], + "disks": [ + { + "disk_size": "5G", + "storage_pool": "local-lvm", + "storage_pool_type": "lvm" + } + ], + "memory": "1024", + "cpu_type": "host", + "scsi_controller": "virtio-scsi-pci", + + "iso_file": "shared:iso/CentOS-8-x86_64-1905-boot.iso", + "os": "l26", + "http_directory":"config", + "boot_wait": "10s", + "boot_command": [ + "<up><tab> ip=dhcp inst.cmdline inst.ks=http://{{.HTTPIP}}:{{.HTTPPort}}/centos8-ks.cfg<enter>" + ], + "ssh_username": "root", + "ssh_timeout": "20m", + "ssh_password": "root", + + "unmount_iso": true, + "template_name": "centos-8", + "template_description": "CentOS 8, generated on {{ isotime }}" + } + ], + "provisioners": [ + { + "type": "shell", + "script": "scripts/cloud-config.sh" + } + ], + "post-processors": [ + { + "type": "manifest", + "output": "{{user `manifest`}}", + "strip_path": true + }, + { + "script": "scripts/post-process.sh", + "type": "shell-local", + "environment_vars": [ + "PM_USER={{user `username`}}", + "PM_PASS={{user `password`}}", + "PM_API_URL={{user `api_url`}}", + "PM_NODE={{user `pve_node`}}", + "PM_POOL={{user `pve_pool`}}", + "PACKER_MANIFEST={{user `manifest`}}" + ] + } + ] +} diff --git a/config/centos8-ks.cfg b/config/centos8-ks.cfg @@ -0,0 +1,36 @@ +#version=RHEL8 +ignoredisk --only-use=sda +clearpart --none --initlabel +autopart --type=lvm + +cmdline + +# Use network installation +repo --name="AppStream" --baseurl="http://mirror.centos.org/centos/8/AppStream/x86_64/os/" +url --url="http://mirror.centos.org/centos/8/BaseOS/x86_64/os/" + +# Keyboard layouts +keyboard --vckeymap=us --xlayouts='us' +# System language +lang en_US.UTF-8 +# System timezone +timezone Europe/Zurich --isUtc + +# Network information +network --bootproto=dhcp --device=link --ipv6=auto --activate +network --hostname=localhost.localdomain + +# Root password +rootpw root + +# Do not configure the X Window System +skipx +# System services +services --enabled="chronyd" + +reboot + +%packages +@^server-product-environment +kexec-tools +%end diff --git a/scripts/cloud-config.sh b/scripts/cloud-config.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +#set -o xtrace + +# install cloud-init +yum install -y cloud-init cloud-utils-growpart + +# change cloud-init defaults +sed -i \ + -e 's/name: cloud-user/name: centos/' \ + /etc/cloud/cloud.cfg +#sed -i \ +# -e 's/127.0.0.1 {{fqdn}}/#127.0.0.1 {{fqdn}}/' \ +# -e '/disable_vmware_customization: false/a manage_etc_hosts: false' \ +# /etc/cloud/templates/hosts.redhat.tmpl diff --git a/scripts/post-process.sh b/scripts/post-process.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +#set -o xtrace + +# https://pve.proxmox.com/wiki/Proxmox_VE_API +# https://pve.proxmox.com/wiki/Cloud-Init_Support#_preparing_cloud_init_templates + +#yum install -y epel-release jq curl + +# read vm id from latest build +vmid=$(jq -r '.builds | sort_by(.build_time) | reverse | .[0].artifact_id' "$PACKER_MANIFEST") + +# pve api authorization +ticket=$(curl -s -d "username=$PM_USER&password=$PM_PASS" "$PM_API_URL/access/ticket") +cookie=$(echo "$ticket" | jq -r ".data.ticket" | sed "s/^/PVEAuthCookie=/") +csrftoken=$(echo "$ticket" | jq -r '.data.CSRFPreventionToken' | sed 's/^/CSRFPreventionToken:/') + +# add cloud-init drive +curl -s -H "$csrftoken" -XPOST -b "$cookie" \ + "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" \ + --data-urlencode scsi1="local-lvm:cloudinit" + +curl -s -XGET -b "$cookie" \ + "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" | jq '.data.scsi1' + +# delete cloud-init drive +#curl -s -H "$csrftoken" -XPOST -b "$cookie" \ +# "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" \ +# --data-urlencode delete="scsi1" +#curl -s -XGET -b "$cookie" \ +# "$PM_API_URL/nodes/$PM_NODE/qemu/$vmid/config" | jq '.data.scsi1'