Originally published on LinkedIn on 2020-05-01.
I really like to automate things. So I also automate the creation and provision of base images for a datacenter environment.
There are some tools which solve this. In my case I prefer packer.io.
Why? Because it is opensource, supports a lot of different technologies, runs on different platforms and so on and so on. And it is simple and lightweight.
So with packer you can, build and provision images in cloud environments but also local with kvm, virtualbox or even hyper-v.
[gerhardsulzberger@localhost packerkvmcentospgsql]$ cat CentOS-7.7-server-x86_64-kvm.json
{
"builders":
[
{
"type": "qemu",
"iso_url": "http://ftp.tugraz.at/mirror/centos/7.7.1908/isos/x86_64/CentOS-7-x86_64-Minimal-1908.iso",
"iso_checksum": "9a2c47d97b9975452f7d582264e9fc16d108ed8252ac6816239a3b58cef5c53d",
"iso_checksum_type": "sha256",
"output_directory": "output_centos_tdhtest",
"shutdown_command": "echo 'packer' | sudo -S shutdown -P now",
"disk_size": "5000M",
"format": "qcow2",
"accelerator": "kvm",
"http_directory": "http",
"ssh_username": "root",
"ssh_password": "changeme",
"ssh_timeout": "20m",
"vm_name": "tdhtest",
"net_device": "virtio-net",
"disk_interface": "virtio",
"boot_wait": "10s",
"boot_command": [
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
]
}
]
}

In case of Redhat images you can create the kickstartfile by the RedHat Kickstart Generator.

The image can be used now as base image. But Packer can be do more for you. It can also Provision the base image with different tools like Ansible, Chef or even PowerShell.
For more information just take a look at the docs of packer.io.
Have fun