I am looking to create a custom Pi image so I can deploy multiple devices quickly. I have looked into a few tutorials on using pi-gen, but I couldn't find one that shows how to install new packages or compile packages inside the image.

Ideally I am looking to preinstall certain utilities, such as vim, OpenVPN, Google MFA, etc, so that I can then generate individual images for my devices through a script that just populates certificates on the image.

Second, I would like to be able to do all compilation of packages such as OpenCV and GStreamer on a more powerful machine and then use the image on the Pi. I have tried doing this using Ansible, and its painful!

I have previously tried to do this via Ansible on each new device, but this is untenable as it extends image generation from a 10-15 minute SD card burning step to a several hour installation process.

I am not sure I understand - are you suggesting that I chroot into the image from a Raspberry Pi? Does it matter what OS I `chroot` into the image from? If I `chroot` from a Mac or a Ubuntu 16.04 machine, will it usually work or are there any kernel-level differences that might break the process?