Packer templates for OpenSLX
Packer-based generation of reference systems using distro's ISOs.
Dependencies
Packer => 0.12.2
Download: https://www.packer.io/downloads.html
Usage
The file 'base.json' contains default variables (VM, SSH) common to all templates,
and should always be included using packer's '-var-file' option. The root password
is expected to be specified as the ROOTPW environment variable!
Basic usage:
ROOTPW=<password> packer build -var-file=base.json <template>
For the rest of the examples, ROOTPW is assumed to be set in the environment.
Usage: Creating base images
Example
Build Ubuntu 16.04.2 LTS template using qemu builder
packer build -var-file=base.json -only=qemu ubuntu-16.04-amd64.json
Same with debug output:
PACKER_LOG=1 PACKER_LOG_FILE=/var/log/packer.log \
packer build -debug -only=qemu -var-file=base.json ubuntu-16.04-amd64.json
A successful build process would generate the disk image as '/', e.g.:
output-qemu-ubuntu-16.04-amd64/ubuntu-16.04-amd64
Additionally, the manifest post-processor creates a manifest.json file in
the working directory containing various information about the generated
artifact, in particular the path to the disk file which can be easily extracted
with jq:
jq -r '.builds[0].files[0].name' < output-qemu-ubuntu-16.04-amd64/manifest.json
Usage: Provisioning base images
The templates provided by this repository only perform minimal OS installations.
Further customizations on base images should be done separately in
a provisioning step. These will be developed in the ansible-roles repository and
will not be further discussed here. The only requirement on the packer build process
is to install the provisioning software and configure its remote access. Since the focus
is on ansible, each provided template installs a SSH server and the ansible packages.
The example below shows how to run a playbook using a special packer template.
The ansible-roles submodule
provides ansible roles and a sample playbook, to buildthe stage3 initramfs using
systemd-init.
Refer to those repos for more information.
Example
Build a stage3 initramfs with dracut inside a previously created image using the
'run-playbook-only' packer template used to only run the 'build-dracut-initramfs'
playbook on a previously generated image
(e.g. output-qemu-ubuntu-16.04-amd64/ubuntu-16.04-amd64):
packer build -var-file=base.json \
-var='image_dir="output-qemu-ubuntu-16.04-amd64"' \
-var='image_name="ubuntu-16.04-amd64"' \
-var='playbook="build-dracut-initramfs.yml"' \
ansible-roles/run-playbook-only.json
The packer artifact is created in 'output-'. This artifact
contains all the development packages needed to build the initramfs, which
can be discarded. Instead, the base image can be used as the main stage4 image.
Notes
Variables set in base.json can be overriden using packer's '-var' options,
e.g. to disable the headless mode:
packer build -var-file=base.json -var='headless=true' <template>
Make sure you first include base.json before overriding a variable defined
in that file or it will not work.
Partitioning the virtual disk is done during the kickstart/preseed installation.
A simple partition scheme is currently used: a dedicated boot partition and a
main system partition labeled as SLX_SYS, using xfs as filesystem. Other
filesystems are also supported, tested were currently ext4 and btrfs. If you
change the filesystem to use you need to adapt your boot configuration file
(SLX_MOUNT_ROOT_OPTIONS). Refer to systemd-init for more infos.
Generated qcow2 image can be further compressed using libvirt tools:
virt-sparsify --compress <qcow2_file> <output_qcow2_file>
Makefile
A simple Makefile to build packer templates is provided for convenience.
Refer to make help
for further instructions.
Example
Build Ubuntu 16.04 LTS with qemu:
make ubuntu-16.04-amd64/base
Generate boot files:
make ubuntu-16.04-amd64/base/boot
This generates the virtual disk image under 'ubuntu-16.04-amd64/base/image'
and the boot files under 'ubuntu-16.04-amd64/base/boot/'.
Only the qemu builder is currently fully supported, which is why it is
always used if detected on the system. Virtualbox and Vmware can be used
to build base images only, provisioning is not yet supported using these.
Note they generate OVF and VMDK files respectively. Using qemu is
currently recommended.
TL;DR
0) Clone repo:
git clone --recursive git://git.openslx.org/openslx-ng/packer-templates
1) Build base image:
make ubuntu-16.04-amd64/base
2) Build initramfs for base image:
make ubuntu-16.04-amd64/base/boot
Results
Produces:
* kernel & initramfs in ubuntu-16.04-amd64/base/boot/
* main qcow2 image under ubuntu-16.04-amd64/base/image
To boot:
* deploy qcow2 image on your dnbd3 server
* deploy kernel and initramfs on http server
* point to the new dnbd3 image in your config file, see template:
* http://git.openslx.org/openslx-ng/systemd-init.git/tree/dev-tools/example-openslx.config