11

Can Packer be used to install and provision a bare metal server? Packer provides webserver with repository packages and preseed/kickstart and can run some other provision softwares(ansible,puppet, chef, etc). Could it be used to install bare metal servers? If yes, how should a packer .json look like?

1 Answers1

10

I had a similar question. I found this issue thread on using Packer with PXE boot.

https://github.com/hashicorp/packer/issues/955

From the thread, Vasiliy Tolstov commented:

[It's] very simple: install all needed stuff inside a VM (for Debian live-boot, for fedora/centos Dracut with the ability to boot from the net). after [building] that [with] packer run the following script (example for Debian):

#!/bin/sh -ex

apt-get -y install squashfs-tools

mkdir -p /mnt/squashfs /squashfs
mount -o bind / /mnt/squashfs

mksquashfs /mnt/squashfs /squashfs/filesystem.squashfs -comp gzip -no-exports -xattrs -noappend -no-recovery -e 
/mnt/squashfs/squashfs/filesystem.squashfs
find /boot -name 'vmlinuz-*' -type f -exec cp {} /squashfs/vmlinuz \;
find /boot -name 'init*' -type f -exec cp {} /squashfs/initrd.img \;

and in packer download artifacts from vm:

{
  "type": "file",
  "direction": "download",
  "sources": [
    "/squashfs/vmlinuz"
  ],
  "destination": "output/{{user `name`}}-squashfs/{{user `name`}}.vmlinuz"
},
{
  "type": "file",
  "direction": "download",
  "sources": [
    "/squashfs/initrd.img"
  ],
  "destination": "output/{{user `name`}}-squashfs/{{user `name`}}.initrd"
},
{
  "type": "file",
  "direction": "download",
  "sources": [
    "/squashfs/filesystem.squashfs"
  ],
  "destination": "output/{{user `name`}}-squashfs/{{user `name`}}.squashfs"
}
Frobbit
  • 216
  • 3
  • 5
  • Welcome to Serverfault! This is not an answer or link-only answer. Please add at least quotation of the part you think answers this question. – Esa Jokinen Aug 09 '17 at 07:01
  • Looking back I agree. How do I retract my answer – Frobbit Aug 09 '17 at 19:48
  • Just edit it to include the actual solution, answer to the question. Link is good to keep as reference, but external links may die and the answer stays here. This way it possibly serves other people than just the OP. – Esa Jokinen Aug 10 '17 at 11:59
  • I found it helpful to learn that the bottom json section was the "file" provisioner in packer: https://www.packer.io/docs/provisioners/file – Zachary Vance Feb 18 '22 at 21:22