mirror of https://github.com/hashicorp/packer
Add complete HCL2 examples + allow to name a singular build.source blocks (#9490)
* in the examples/hcl folder * add possibility to name singular build.source blocks to differentiate their output and to filter on thempull/9523/head
parent
445cf12b65
commit
3d371a2d5d
@ -0,0 +1,36 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
qemu) exit 0 ;;
|
||||
esac
|
||||
|
||||
# Whiteout root
|
||||
count=$(df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}')
|
||||
count=$(($count-1))
|
||||
dd if=/dev/zero of=/tmp/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
|
||||
rm /tmp/whitespace
|
||||
|
||||
# Whiteout /boot
|
||||
count=$(df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}')
|
||||
count=$(($count-1))
|
||||
dd if=/dev/zero of=/boot/whitespace bs=1M count=$count || echo "dd exit code $? is suppressed";
|
||||
rm /boot/whitespace
|
||||
|
||||
set +e
|
||||
swapuuid="`/sbin/blkid -o value -l -s UUID -t TYPE=swap`";
|
||||
case "$?" in
|
||||
2|0) ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
set -e
|
||||
|
||||
if [ "x${swapuuid}" != "x" ]; then
|
||||
# Whiteout the swap partition to reduce box size
|
||||
# Swap is disabled till reboot
|
||||
swappart="`readlink -f /dev/disk/by-uuid/$swapuuid`";
|
||||
/sbin/swapoff "$swappart";
|
||||
dd if=/dev/zero of="$swappart" bs=1M || echo "dd exit code $? is suppressed";
|
||||
/sbin/mkswap -U "$swapuuid" "$swappart";
|
||||
fi
|
||||
|
||||
sync;
|
||||
@ -0,0 +1,35 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
# set a default HOME_DIR environment variable if not set
|
||||
HOME_DIR="${HOME_DIR:-/home/vagrant}";
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
parallels-iso|parallels-pvm)
|
||||
mkdir -p /tmp/parallels;
|
||||
mount -o loop $HOME_DIR/prl-tools-lin.iso /tmp/parallels;
|
||||
VER="`cat /tmp/parallels/version`";
|
||||
|
||||
echo "Parallels Tools Version: $VER";
|
||||
|
||||
/tmp/parallels/install --install-unattended-with-deps \
|
||||
|| (code="$?"; \
|
||||
echo "Parallels tools installation exited $code, attempting" \
|
||||
"to output /var/log/parallels-tools-install.log"; \
|
||||
cat /var/log/parallels-tools-install.log; \
|
||||
exit $code);
|
||||
umount /tmp/parallels;
|
||||
rm -rf /tmp/parallels;
|
||||
rm -f $HOME_DIR/*.iso;
|
||||
|
||||
# Parallels Tools for Linux includes native auto-mount script,
|
||||
# which causes losing some of Vagrant-relative shared folders.
|
||||
# So, we should disable this behavior.
|
||||
# https://github.com/Parallels/vagrant-parallels/issues/325#issuecomment-418727113
|
||||
auto_mount_script='/usr/bin/prlfsmountd'
|
||||
if [ -f "${auto_mount_script}" ]; then
|
||||
echo -e '#!/bin/sh\n'\
|
||||
'# Shared folders auto-mount is disabled by Vagrant ' \
|
||||
> "${auto_mount_script}"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
@ -0,0 +1,20 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
SSHD_CONFIG="/etc/ssh/sshd_config"
|
||||
|
||||
# ensure that there is a trailing newline before attempting to concatenate
|
||||
sed -i -e '$a\' "$SSHD_CONFIG"
|
||||
|
||||
USEDNS="UseDNS no"
|
||||
if grep -q -E "^[[:space:]]*UseDNS" "$SSHD_CONFIG"; then
|
||||
sed -i "s/^\s*UseDNS.*/${USEDNS}/" "$SSHD_CONFIG"
|
||||
else
|
||||
echo "$USEDNS" >>"$SSHD_CONFIG"
|
||||
fi
|
||||
|
||||
GSSAPI="GSSAPIAuthentication no"
|
||||
if grep -q -E "^[[:space:]]*GSSAPIAuthentication" "$SSHD_CONFIG"; then
|
||||
sed -i "s/^\s*GSSAPIAuthentication.*/${GSSAPI}/" "$SSHD_CONFIG"
|
||||
else
|
||||
echo "$GSSAPI" >>"$SSHD_CONFIG"
|
||||
fi
|
||||
@ -0,0 +1,19 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
# set a default HOME_DIR environment variable if not set
|
||||
HOME_DIR="${HOME_DIR:-/home/vagrant}";
|
||||
|
||||
pubkey_url="https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub";
|
||||
mkdir -p $HOME_DIR/.ssh;
|
||||
if command -v wget >/dev/null 2>&1; then
|
||||
wget --no-check-certificate "$pubkey_url" -O $HOME_DIR/.ssh/authorized_keys;
|
||||
elif command -v curl >/dev/null 2>&1; then
|
||||
curl --insecure --location "$pubkey_url" > $HOME_DIR/.ssh/authorized_keys;
|
||||
elif command -v fetch >/dev/null 2>&1; then
|
||||
fetch -am -o $HOME_DIR/.ssh/authorized_keys "$pubkey_url";
|
||||
else
|
||||
echo "Cannot download vagrant public key";
|
||||
exit 1;
|
||||
fi
|
||||
chown -R vagrant $HOME_DIR/.ssh;
|
||||
chmod -R go-rwsx $HOME_DIR/.ssh;
|
||||
@ -0,0 +1,19 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
# set a default HOME_DIR environment variable if not set
|
||||
HOME_DIR="${HOME_DIR:-/home/vagrant}";
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
virtualbox-iso|virtualbox-ovf)
|
||||
VER="`cat $HOME_DIR/.vbox_version`";
|
||||
ISO="VBoxGuestAdditions_$VER.iso";
|
||||
mkdir -p /tmp/vbox;
|
||||
mount -o loop $HOME_DIR/$ISO /tmp/vbox;
|
||||
sh /tmp/vbox/VBoxLinuxAdditions.run \
|
||||
|| echo "VBoxLinuxAdditions.run exited $? and is suppressed." \
|
||||
"For more read https://www.virtualbox.org/ticket/12479";
|
||||
umount /tmp/vbox;
|
||||
rm -rf /tmp/vbox;
|
||||
rm -f $HOME_DIR/*.iso;
|
||||
;;
|
||||
esac
|
||||
@ -0,0 +1,34 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
# set a default HOME_DIR environment variable if not set
|
||||
HOME_DIR="${HOME_DIR:-/home/vagrant}";
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
vmware-iso|vmware-vmx)
|
||||
|
||||
# make sure we have /sbin in our path. RHEL systems lack this
|
||||
PATH=/sbin:$PATH
|
||||
export PATH
|
||||
|
||||
mkdir -p /tmp/vmware;
|
||||
mkdir -p /tmp/vmware-archive;
|
||||
mount -o loop $HOME_DIR/linux.iso /tmp/vmware;
|
||||
|
||||
TOOLS_PATH="`ls /tmp/vmware/VMwareTools-*.tar.gz`";
|
||||
VER="`echo "${TOOLS_PATH}" | cut -f2 -d'-'`";
|
||||
MAJ_VER="`echo ${VER} | cut -d '.' -f 1`";
|
||||
|
||||
echo "VMware Tools Version: $VER";
|
||||
|
||||
tar xzf ${TOOLS_PATH} -C /tmp/vmware-archive;
|
||||
if [ "${MAJ_VER}" -lt "10" ]; then
|
||||
/tmp/vmware-archive/vmware-tools-distrib/vmware-install.pl --default;
|
||||
else
|
||||
/tmp/vmware-archive/vmware-tools-distrib/vmware-install.pl --force-install;
|
||||
fi
|
||||
umount /tmp/vmware;
|
||||
rm -rf /tmp/vmware;
|
||||
rm -rf /tmp/vmware-archive;
|
||||
rm -f $HOME_DIR/*.iso;
|
||||
;;
|
||||
esac
|
||||
@ -0,0 +1,6 @@
|
||||
# Basic HCL2 Ubuntu builders
|
||||
|
||||
Taking the [chef/bento](https://github.com/chef/bento) repo as an example.
|
||||
|
||||
I recommend you start by reading the build.pkr.hcl file and the
|
||||
comments/description there.
|
||||
@ -0,0 +1,99 @@
|
||||
|
||||
build {
|
||||
name = "ubuntu"
|
||||
description = <<EOF
|
||||
This build creates ubuntu images for ubuntu versions :
|
||||
* 16.04
|
||||
* 18.04
|
||||
For the following builers :
|
||||
* virtualbox-iso
|
||||
* parallels-iso
|
||||
* vmware-iso
|
||||
* qemu
|
||||
* vsphere-iso
|
||||
EOF
|
||||
|
||||
// the common fields of the source blocks are defined in the
|
||||
// source.builder-type.pkr.hcl files, here we only set the fields specific to
|
||||
// the different versions of ubuntu.
|
||||
source "source.virtualbox-iso.base-ubuntu-amd64" {
|
||||
name = "16.04"
|
||||
iso_url = local.iso_url_ubuntu_1604
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1604}"
|
||||
output_directory = "virtualbox_iso_ubuntu_1604_amd64"
|
||||
boot_command = local.ubuntu_1604_boot_command
|
||||
boot_wait = "10s"
|
||||
}
|
||||
|
||||
source "source.virtualbox-iso.base-ubuntu-amd64" {
|
||||
name = "18.04"
|
||||
iso_url = local.iso_url_ubuntu_1804
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1804}"
|
||||
output_directory = "virtualbox_iso_ubuntu_1804_amd64"
|
||||
boot_command = local.ubuntu_1804_boot_command
|
||||
boot_wait = "5s"
|
||||
}
|
||||
|
||||
source "source.parallels-iso.base-ubuntu-amd64" {
|
||||
name = "16.04"
|
||||
iso_url = local.iso_url_ubuntu_1604
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1604}"
|
||||
output_directory = "parallels_iso_ubuntu_1604_amd64"
|
||||
boot_command = local.ubuntu_1604_boot_command
|
||||
}
|
||||
|
||||
source "source.parallels-iso.base-ubuntu-amd64" {
|
||||
name = "18.04"
|
||||
iso_url = local.iso_url_ubuntu_1804
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1804}"
|
||||
output_directory = "parallels_iso_ubuntu_1804_amd64"
|
||||
boot_command = local.ubuntu_1804_boot_command
|
||||
}
|
||||
|
||||
source "source.vmware-iso.base-ubuntu-amd64" {
|
||||
name = "16.04"
|
||||
iso_url = local.iso_url_ubuntu_1604
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1604}"
|
||||
output_directory = "vmware_iso_ubuntu_1604_amd64"
|
||||
boot_command = local.ubuntu_1604_boot_command
|
||||
}
|
||||
|
||||
source "source.vmware-iso.base-ubuntu-amd64" {
|
||||
name = "18.04"
|
||||
iso_url = local.iso_url_ubuntu_1804
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1804}"
|
||||
output_directory = "vmware_iso_ubuntu_1804_amd64"
|
||||
boot_command = local.ubuntu_1804_boot_command
|
||||
}
|
||||
|
||||
source "source.qemu.base-ubuntu-amd64" {
|
||||
name = "16.04"
|
||||
iso_url = local.iso_url_ubuntu_1604
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1604}"
|
||||
output_directory = "qemu_iso_ubuntu_1604_amd64"
|
||||
boot_command = local.ubuntu_1604_boot_command
|
||||
}
|
||||
|
||||
source "source.qemu.base-ubuntu-amd64" {
|
||||
name = "18.04"
|
||||
iso_url = local.iso_url_ubuntu_1804
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1804}"
|
||||
output_directory = "qemu_iso_ubuntu_1804_amd64"
|
||||
boot_command = local.ubuntu_1804_boot_command
|
||||
}
|
||||
|
||||
source "source.vsphere-iso.base-ubuntu-amd64" {
|
||||
name = "16.04"
|
||||
vm_name = "ubuntu-16.04"
|
||||
iso_url = local.iso_url_ubuntu_1604
|
||||
iso_checksum = "file:${local.iso_checksum_url_ubuntu_1604}"
|
||||
}
|
||||
|
||||
provisioner "shell" {
|
||||
environment_vars = [ "HOME_DIR=/home/vagrant" ]
|
||||
execute_command = "echo 'vagrant' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'"
|
||||
expect_disconnect = true
|
||||
// fileset will list files in etc/scripts sorted in an alphanumerical way.
|
||||
scripts = fileset(".", "etc/scripts/*.sh")
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
choose-mirror-bin mirror/http/proxy string
|
||||
d-i base-installer/kernel/override-image string linux-server
|
||||
d-i clock-setup/utc boolean true
|
||||
d-i clock-setup/utc-auto boolean true
|
||||
d-i finish-install/reboot_in_progress note
|
||||
d-i grub-installer/only_debian boolean true
|
||||
d-i grub-installer/with_other_os boolean true
|
||||
d-i mirror/country string manual
|
||||
d-i mirror/http/directory string /ubuntu/
|
||||
d-i mirror/http/hostname string archive.ubuntu.com
|
||||
d-i mirror/http/proxy string
|
||||
d-i partman-auto-lvm/guided_size string max
|
||||
d-i partman-auto/choose_recipe select atomic
|
||||
d-i partman-auto/method string lvm
|
||||
d-i partman-lvm/confirm boolean true
|
||||
d-i partman-lvm/confirm boolean true
|
||||
d-i partman-lvm/confirm_nooverwrite boolean true
|
||||
d-i partman-lvm/device_remove_lvm boolean true
|
||||
d-i partman/choose_partition select finish
|
||||
d-i partman/confirm boolean true
|
||||
d-i partman/confirm_nooverwrite boolean true
|
||||
d-i partman/confirm_write_new_label boolean true
|
||||
d-i passwd/user-fullname string vagrant
|
||||
d-i passwd/user-uid string 1000
|
||||
d-i passwd/user-password password vagrant
|
||||
d-i passwd/user-password-again password vagrant
|
||||
d-i passwd/username string vagrant
|
||||
d-i pkgsel/include string openssh-server cryptsetup build-essential libssl-dev libreadline-dev zlib1g-dev linux-source dkms nfs-common linux-headers-$(uname -r) perl cifs-utils software-properties-common rsync ifupdown
|
||||
d-i pkgsel/install-language-support boolean false
|
||||
d-i pkgsel/update-policy select none
|
||||
d-i pkgsel/upgrade select full-upgrade
|
||||
d-i time/zone string UTC
|
||||
d-i user-setup/allow-password-weak boolean true
|
||||
d-i user-setup/encrypt-home boolean false
|
||||
tasksel tasksel/first multiselect standard, server
|
||||
@ -0,0 +1,68 @@
|
||||
#
|
||||
# Based upon: https://help.ubuntu.com/12.04/installation-guide/example-preseed.txt
|
||||
#
|
||||
|
||||
# localisation
|
||||
|
||||
d-i debian-installer/locale string en_US.utf8
|
||||
d-i console-setup/ask_detect boolean false
|
||||
d-i keyboard-configuration/layoutcode string us
|
||||
|
||||
# networking
|
||||
# Static network configuration.
|
||||
d-i netcfg/disable_autoconfig boolean true
|
||||
d-i netcfg/get_nameservers string 8.8.8.8
|
||||
d-i netcfg/get_netmask string 255.255.255.248
|
||||
d-i netcfg/confirm_static boolean true
|
||||
|
||||
|
||||
# d-i netcfg/choose_interface select auto
|
||||
# d-i netcfg/get_hostname string unassigned-hostname
|
||||
# d-i netcfg/get_domain string unassigned-domain
|
||||
# d-i netcfg/wireless_wep string
|
||||
|
||||
# apt mirrors
|
||||
d-i mirror/country string manual
|
||||
d-i mirror/http/directory string /ubuntu/
|
||||
d-i mirror/http/hostname string archive.ubuntu.com
|
||||
d-i mirror/http/proxy string
|
||||
|
||||
# clock and time zone
|
||||
d-i clock-setup/utc boolean true
|
||||
d-i time/zone string GMT
|
||||
d-i clock-setup/ntp boolean true
|
||||
|
||||
# partitioning
|
||||
d-i partman-auto/method string lvm
|
||||
d-i partman-lvm/device_remove_lvm boolean true
|
||||
d-i partman-md/device_remove_md boolean true
|
||||
d-i partman-lvm/confirm boolean true
|
||||
d-i partman-lvm/confirm_nooverwrite boolean true
|
||||
d-i partman-auto-lvm/guided_size string max
|
||||
d-i partman-auto/choose_recipe select atomic
|
||||
d-i partman-partitioning/confirm_write_new_label boolean true
|
||||
d-i partman/choose_partition select finish
|
||||
d-i partman/confirm boolean true
|
||||
d-i partman/confirm_nooverwrite boolean true
|
||||
|
||||
# users
|
||||
d-i passwd/user-fullname string Vagrant
|
||||
d-i passwd/username string vagrant
|
||||
d-i passwd/user-password password vagrant
|
||||
d-i passwd/user-password-again password vagrant
|
||||
d-i user-setup/allow-password-weak boolean true
|
||||
d-i user-setup/encrypt-home boolean false
|
||||
|
||||
# packages
|
||||
tasksel tasksel/first multiselect standard, ubuntu-server
|
||||
d-i pkgsel/install-language-support boolean false
|
||||
d-i pkgsel/include string openssh-server nfs-common open-vm-tools
|
||||
d-i pkgsel/upgrade select full-upgrade
|
||||
d-i pkgsel/update-policy select none
|
||||
# postfix postfix/main_mailer_type select No configuration
|
||||
|
||||
# boot loader
|
||||
d-i grub-installer/only_debian boolean true
|
||||
|
||||
# hide the shutdown notice
|
||||
d-i finish-install/reboot_in_progress note
|
||||
@ -0,0 +1,40 @@
|
||||
#!/bin/sh -eux
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
ubuntu_version="`lsb_release -r | awk '{print $2}'`";
|
||||
major_version="`echo $ubuntu_version | awk -F. '{print $1}'`";
|
||||
|
||||
# Disable release-upgrades
|
||||
sed -i.bak 's/^Prompt=.*$/Prompt=never/' /etc/update-manager/release-upgrades;
|
||||
|
||||
# Disable systemd apt timers/services
|
||||
if [ "$major_version" -ge "16" ]; then
|
||||
systemctl stop apt-daily.timer;
|
||||
systemctl stop apt-daily-upgrade.timer;
|
||||
systemctl disable apt-daily.timer;
|
||||
systemctl disable apt-daily-upgrade.timer;
|
||||
systemctl mask apt-daily.service;
|
||||
systemctl mask apt-daily-upgrade.service;
|
||||
systemctl daemon-reload;
|
||||
fi
|
||||
|
||||
# Disable periodic activities of apt to be safe
|
||||
cat <<EOF >/etc/apt/apt.conf.d/10periodic;
|
||||
APT::Periodic::Enable "0";
|
||||
APT::Periodic::Update-Package-Lists "0";
|
||||
APT::Periodic::Download-Upgradeable-Packages "0";
|
||||
APT::Periodic::AutocleanInterval "0";
|
||||
APT::Periodic::Unattended-Upgrade "0";
|
||||
EOF
|
||||
|
||||
# Clean and nuke the package from orbit
|
||||
rm -rf /var/log/unattended-upgrades;
|
||||
apt-get -y purge unattended-upgrades;
|
||||
|
||||
# Update the package list
|
||||
apt-get -y update;
|
||||
|
||||
# Upgrade all installed packages incl. kernel and kernel headers
|
||||
apt-get -y dist-upgrade -o Dpkg::Options::="--force-confnew";
|
||||
|
||||
reboot
|
||||
@ -0,0 +1 @@
|
||||
../../../../_common/sshd.sh
|
||||
@ -0,0 +1,25 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
ubuntu_version="`lsb_release -r | awk '{print $2}'`";
|
||||
major_version="`echo $ubuntu_version | awk -F. '{print $1}'`";
|
||||
|
||||
if [ "$major_version" -ge "18" ]; then
|
||||
echo "Create netplan config for eth0"
|
||||
cat <<EOF >/etc/netplan/01-netcfg.yaml;
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
eth0:
|
||||
dhcp4: true
|
||||
EOF
|
||||
else
|
||||
# Adding a 2 sec delay to the interface up, to make the dhclient happy
|
||||
echo "pre-up sleep 2" >> /etc/network/interfaces;
|
||||
fi
|
||||
|
||||
if [ "$major_version" -ge "16" ]; then
|
||||
# Disable Predictable Network Interface names and use eth0
|
||||
sed -i 's/en[[:alnum:]]*/eth0/g' /etc/network/interfaces;
|
||||
sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 \1"/g' /etc/default/grub;
|
||||
update-grub;
|
||||
fi
|
||||
@ -0,0 +1,7 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
sed -i -e '/Defaults\s\+env_reset/a Defaults\texempt_group=sudo' /etc/sudoers;
|
||||
|
||||
# Set up password-less sudo for the vagrant user
|
||||
echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/99_vagrant;
|
||||
chmod 440 /etc/sudoers.d/99_vagrant;
|
||||
@ -0,0 +1 @@
|
||||
../../../../_common/vagrant.sh
|
||||
@ -0,0 +1 @@
|
||||
../../../../_common/virtualbox.sh
|
||||
@ -0,0 +1,10 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
vmware-iso|vmware-vmx)
|
||||
apt-get install -y open-vm-tools;
|
||||
mkdir /mnt/hgfs;
|
||||
systemctl enable open-vm-tools
|
||||
systemctl start open-vm-tools
|
||||
echo "platform specific vmware.sh executed";
|
||||
esac
|
||||
@ -0,0 +1 @@
|
||||
../../../../_common/parallels.sh
|
||||
@ -0,0 +1,12 @@
|
||||
#!/bin/sh -eux
|
||||
ubuntu_version="`lsb_release -r | awk '{print $2}'`";
|
||||
major_version="`echo $ubuntu_version | awk -F. '{print $1}'`";
|
||||
|
||||
case "$PACKER_BUILDER_TYPE" in
|
||||
hyperv-iso)
|
||||
if [ "$major_version" -eq "16" ]; then
|
||||
apt-get install -y linux-tools-virtual-lts-xenial linux-cloud-tools-virtual-lts-xenial;
|
||||
else
|
||||
apt-get -y install linux-image-virtual linux-tools-virtual linux-cloud-tools-virtual;
|
||||
fi
|
||||
esac
|
||||
@ -0,0 +1,81 @@
|
||||
#!/bin/sh -eux
|
||||
|
||||
# Delete all Linux headers
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep 'linux-headers' \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Remove specific Linux kernels, such as linux-image-3.11.0-15-generic but
|
||||
# keeps the current kernel and does not touch the virtual packages,
|
||||
# e.g. 'linux-image-generic', etc.
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep 'linux-image-.*-generic' \
|
||||
| grep -v `uname -r` \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Delete Linux source
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep linux-source \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Delete development packages
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep -- '-dev$' \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# delete docs packages
|
||||
dpkg --list \
|
||||
| awk '{ print $2 }' \
|
||||
| grep -- '-doc$' \
|
||||
| xargs apt-get -y purge;
|
||||
|
||||
# Delete X11 libraries
|
||||
apt-get -y purge libx11-data xauth libxmuu1 libxcb1 libx11-6 libxext6;
|
||||
|
||||
# Delete obsolete networking
|
||||
apt-get -y purge ppp pppconfig pppoeconf;
|
||||
|
||||
# Delete oddities
|
||||
apt-get -y purge popularity-contest installation-report command-not-found friendly-recovery bash-completion fonts-ubuntu-font-family-console laptop-detect;
|
||||
|
||||
# 19.10+ don't have this package so fail gracefully
|
||||
apt-get -y purge command-not-found-data || true;
|
||||
|
||||
# Exlude the files we don't need w/o uninstalling linux-firmware
|
||||
echo "==> Setup dpkg excludes for linux-firmware"
|
||||
cat <<_EOF_ | cat >> /etc/dpkg/dpkg.cfg.d/excludes
|
||||
#BENTO-BEGIN
|
||||
path-exclude=/lib/firmware/*
|
||||
path-exclude=/usr/share/doc/linux-firmware/*
|
||||
#BENTO-END
|
||||
_EOF_
|
||||
|
||||
# Delete the massive firmware packages
|
||||
rm -rf /lib/firmware/*
|
||||
rm -rf /usr/share/doc/linux-firmware/*
|
||||
|
||||
apt-get -y autoremove;
|
||||
apt-get -y clean;
|
||||
|
||||
# Remove docs
|
||||
rm -rf /usr/share/doc/*
|
||||
|
||||
# Remove caches
|
||||
find /var/cache -type f -exec rm -rf {} \;
|
||||
|
||||
# truncate any logs that have built up during the install
|
||||
find /var/log -type f -exec truncate --size=0 {} \;
|
||||
|
||||
# Blank netplan machine-id (DUID) so machines get unique ID generated on boot.
|
||||
truncate -s 0 /etc/machine-id
|
||||
|
||||
# remove the contents of /tmp and /var/tmp
|
||||
rm -rf /tmp/* /var/tmp/*
|
||||
|
||||
# clear the history so our install isn't there
|
||||
export HISTSIZE=0
|
||||
rm -f /root/.wget-hsts
|
||||
@ -0,0 +1 @@
|
||||
../../../../_common/minimize.sh
|
||||
@ -0,0 +1,13 @@
|
||||
|
||||
source "parallels-iso" "base-ubuntu-amd64" {
|
||||
boot_wait = "10s"
|
||||
guest_os_type = "ubuntu"
|
||||
http_directory = local.http_directory
|
||||
parallels_tools_flavor = "lin"
|
||||
prlctl_version_file = ".prlctl_version"
|
||||
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
|
||||
ssh_password = "vagrant"
|
||||
ssh_port = 22
|
||||
ssh_timeout = "10000s"
|
||||
ssh_username = "vagrant"
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
source "qemu" "base-ubuntu-amd64" {
|
||||
headless = var.headless
|
||||
floppy_files = [
|
||||
"${local.http_directory}/preseed.cfg",
|
||||
]
|
||||
http_directory = local.http_directory
|
||||
shutdown_command = "echo 'vagrant'|sudo -S shutdown -P now"
|
||||
ssh_password = "vagrant"
|
||||
ssh_username = "vagrant"
|
||||
ssh_wait_timeout = "50m"
|
||||
disk_size = 5000
|
||||
disk_interface = "virtio-scsi"
|
||||
memory = 512 * 4
|
||||
cpus = 4
|
||||
boot_wait = "5s"
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
source "virtualbox-iso" "base-ubuntu-amd64" {
|
||||
headless = var.headless
|
||||
guest_os_type = "Ubuntu_64"
|
||||
http_directory = local.http_directory
|
||||
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
|
||||
ssh_username = "vagrant"
|
||||
ssh_password = "vagrant"
|
||||
ssh_port = 22
|
||||
ssh_wait_timeout = "15m"
|
||||
hard_drive_interface = "sata"
|
||||
virtualbox_version_file = ".vbox_version"
|
||||
guest_additions_path = "VBoxGuestAdditions_{{.Version}}.iso"
|
||||
guest_additions_url = var.guest_additions_url
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
source "vmware-iso" "base-ubuntu-amd64" {
|
||||
headless = var.headless
|
||||
boot_wait = "10s"
|
||||
guest_os_type = "ubuntu-64"
|
||||
http_directory = local.http_directory
|
||||
shutdown_command = "echo 'vagrant' | sudo -S shutdown -P now"
|
||||
ssh_password = "vagrant"
|
||||
ssh_port = 22
|
||||
ssh_timeout = "10000s"
|
||||
ssh_username = "vagrant"
|
||||
tools_upload_flavor = "linux"
|
||||
vmx_data = {
|
||||
"cpuid.coresPerSocket" = "1"
|
||||
"ethernet0.pciSlotNumber" = "32"
|
||||
}
|
||||
vmx_remove_ethernet_interfaces = true
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
// I use the following config with direnv and set the following values:
|
||||
// export PKR_VAR_bastion_host=""
|
||||
// export PKR_VAR_bastion_user=""
|
||||
// export PKR_VAR_datacenter_name=""
|
||||
// export PKR_VAR_esxi_host=""
|
||||
// export PKR_VAR_esxi_password=""
|
||||
// export PKR_VAR_esxi_user=""
|
||||
// export PKR_VAR_vcenter_endpoint=""
|
||||
// export PKR_VAR_vcenter_password=""
|
||||
// export PKR_VAR_vcenter_user=""
|
||||
// export PKR_VAR_vm_ip=""
|
||||
// export PKR_VAR_gateway_ip=""
|
||||
|
||||
variable "vcenter_endpoint" { type = string }
|
||||
variable "vcenter_user" { type = string }
|
||||
variable "vcenter_password" { type = string }
|
||||
variable "esxi_host" { type = string }
|
||||
variable "datacenter_name" { type = string }
|
||||
variable "vm_ip" { type = string }
|
||||
variable "gateway_ip" { type = string }
|
||||
variable "datastore" {
|
||||
default = "datastore1"
|
||||
}
|
||||
|
||||
source "vsphere-iso" "base-ubuntu-amd64" {
|
||||
vcenter_server = var.vcenter_endpoint
|
||||
username = var.vcenter_user
|
||||
password = var.vcenter_password
|
||||
host = var.esxi_host
|
||||
insecure_connection = true
|
||||
|
||||
datacenter = var.datacenter_name
|
||||
datastore = "datastore1"
|
||||
|
||||
ssh_password = "vagrant"
|
||||
ssh_username = "vagrant"
|
||||
|
||||
CPUs = 1
|
||||
RAM = 512 * 2
|
||||
RAM_reserve_all = true
|
||||
|
||||
disk_controller_type = "pvscsi"
|
||||
floppy_files = [
|
||||
"etc/http/preseed_hardcoded_ip.cfg"
|
||||
]
|
||||
guest_os_type = "ubuntu64Guest"
|
||||
network_adapters {
|
||||
network = "VM Network"
|
||||
network_card = "vmxnet3"
|
||||
}
|
||||
storage {
|
||||
disk_size = 32768
|
||||
disk_thin_provisioned = true
|
||||
}
|
||||
|
||||
boot_command = [
|
||||
"<enter><wait><f6><wait><esc><wait>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs>",
|
||||
"/install/vmlinuz",
|
||||
" initrd=/install/initrd.gz",
|
||||
" priority=critical",
|
||||
" locale=en_US",
|
||||
" file=/media/preseed_hardcoded_ip.cfg",
|
||||
" netcfg/get_ipaddress=${var.vm_ip}",
|
||||
" netcfg/get_gateway=${var.gateway_ip}",
|
||||
"<enter>"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
variable "ubuntu_1604_version" {
|
||||
default = "16.04.6"
|
||||
}
|
||||
|
||||
locals {
|
||||
iso_url_ubuntu_1604 = "http://releases.ubuntu.com/releases/16.04/ubuntu-${var.ubuntu_1604_version}-server-amd64.iso"
|
||||
iso_checksum_url_ubuntu_1604 = "http://releases.ubuntu.com/releases/16.04/SHA256SUMS"
|
||||
ubuntu_1604_boot_command = [
|
||||
"<enter><wait><f6><esc><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"<bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs><bs>",
|
||||
"/install/vmlinuz<wait>",
|
||||
" auto<wait>",
|
||||
" console-setup/ask_detect=false<wait>",
|
||||
" console-setup/layoutcode=us<wait>",
|
||||
" console-setup/modelcode=pc105<wait>",
|
||||
" debconf/frontend=noninteractive<wait>",
|
||||
" debian-installer=en_US.UTF-8<wait>",
|
||||
" fb=false<wait>",
|
||||
" initrd=/install/initrd.gz<wait>",
|
||||
" kbd-chooser/method=us<wait>",
|
||||
" keyboard-configuration/layout=USA<wait>",
|
||||
" keyboard-configuration/variant=USA<wait>",
|
||||
" locale=en_US.UTF-8<wait>",
|
||||
" netcfg/get_domain=vm<wait>",
|
||||
" netcfg/get_hostname=vagrant<wait>",
|
||||
" grub-installer/bootdev=/dev/sda<wait>",
|
||||
" noapic<wait>",
|
||||
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/${var.preseed_path}<wait>",
|
||||
" -- <wait>",
|
||||
"<enter><wait>"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
variable "ubuntu_1804_version" {
|
||||
default = "18.04.4"
|
||||
}
|
||||
|
||||
locals {
|
||||
iso_url_ubuntu_1804 = "http://cdimage.ubuntu.com/ubuntu/releases/18.04/release/ubuntu-18.04.4-server-amd64.iso"
|
||||
iso_checksum_url_ubuntu_1804 = "http://cdimage.ubuntu.com/ubuntu/releases/18.04/release/SHA256SUMS"
|
||||
ubuntu_1804_boot_command = [
|
||||
"<esc><wait>",
|
||||
"<esc><wait>",
|
||||
"<enter><wait>",
|
||||
"/install/vmlinuz<wait>",
|
||||
" auto<wait>",
|
||||
" console-setup/ask_detect=false<wait>",
|
||||
" console-setup/layoutcode=us<wait>",
|
||||
" console-setup/modelcode=pc105<wait>",
|
||||
" debconf/frontend=noninteractive<wait>",
|
||||
" debian-installer=en_US.UTF-8<wait>",
|
||||
" fb=false<wait>",
|
||||
" initrd=/install/initrd.gz<wait>",
|
||||
" kbd-chooser/method=us<wait>",
|
||||
" keyboard-configuration/layout=USA<wait>",
|
||||
" keyboard-configuration/variant=USA<wait>",
|
||||
" locale=en_US.UTF-8<wait>",
|
||||
" netcfg/get_domain=vm<wait>",
|
||||
" netcfg/get_hostname=vagrant<wait>",
|
||||
" grub-installer/bootdev=/dev/sda<wait>",
|
||||
" noapic<wait>",
|
||||
" preseed/url=http://{{ .HTTPIP }}:{{ .HTTPPort }}/${var.preseed_path}<wait>",
|
||||
" -- <wait>",
|
||||
"<enter><wait>"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
|
||||
variable "preseed_path" {
|
||||
type = string
|
||||
default = "preseed.cfg"
|
||||
}
|
||||
|
||||
variable "guest_additions_url" {
|
||||
type = string
|
||||
default = ""
|
||||
}
|
||||
|
||||
variable "headless" {
|
||||
type = bool
|
||||
default = true
|
||||
}
|
||||
|
||||
locals {
|
||||
// fileset lists all files in the http directory as a set, we convert that
|
||||
// set to a list of strings and we then take the directory of the first
|
||||
// value. This validates that the http directory exists even before starting
|
||||
// any builder/provisioner.
|
||||
http_directory = dirname(convert(fileset(".", "etc/http/*"), list(string))[0])
|
||||
}
|
||||
Loading…
Reference in new issue