Date Added | Description | Link |
---|---|---|
2019-11-24 | Jetbrains Packer Builder Vsphere | https://github.com/jetbrains-infra/packer-builder-vsphere |
2019-11-24 | VMware Guestinfo Cloud-Init | https://github.com/vmware/cloud-init-vmware-guestinfo/releases |
Centos Kickstart Reference | https://docs.centos.org/en-US/centos/install-guide/Kickstart2/ | RHEL7 Kickstart Guide | https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-simple-install-kickstart|
We are going to build for centos-7, which is not one of the examples that Jetbrains provides. However, there are several pull requests on the github repo which contain some examples to work from. At a high level, we’re going to use packer to build a centos vm from a base ISO using kickstart, configure it further using cloud-init, and finally use packer provisioners to run some hardening scripts against it. The goal is a template vm (either in or out of a VMware Content Library) that can be provisioned via govc or terraform as a clone (linked or full)
This is the main packer scipt. The first part executes now (the builder part), and the rest executes after the image is built by kickstart and cloud-init (the provisioner part). Note that we use vault to store the credentials in the configuration file
This is a redhat format unattended install script which does the following:
https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm
. you just need to make sure this repo is added to your ks.cfg.This is the bootstrap cloud init script. Once kickstart reboots the machine and it comes up, cloud-init takes over the configuration of the machine.
It can do a lot more. There are seveal other things that should go here. Honestly you could probably put all of the rest of the stuff that gets executed by packer provisioners (see below) in the cloud-init script if you wanted to. - yum repo configuration (point to internal repos) - puppet rpm installation from that repo - any other configuration management
This is the “provisioner” part of the Packer script. What we use this for is to ssh into the image as the centos user and execute a series of shell scripts as root using sudo. The reason we do it this way is because we’ve already locked the root user down in previous steps. These scripts are designed to run on the image just prior to it being shut down, and handle genericization of the image. This includes
Once this is complete, packer shuts down the image, and turns it into a template in vcenter that you can clone.
for the vsphere configuration, there are a number of ways to do this, including standalone esx. This is just how I did it. the jetbrains git repo has more information, and the parameters you need might change depending on your approach)
network config (DHCP or static)
network --device=eth0 --bootproto=dhcp --activate
network --device=eth0 --bootproto=static --ip=10.4.20.161 --netmask=255.255.255.0 --gateway=10.4.20.1 --nameserver=10.4.20.211 --hostname=centos7 --activate
yum repos
repo --name="base" --baseurl="http://mirror.centos.org/centos/$releasever/os/$basearch"
repo --name="updates" --baseurl="http://mirror.centos.org/centos/$releasever/updates/$basearch"
repo --name="epel" --baseurl="http://download.fedoraproject.org/pub/epel/$releasever/$basearch"
repo --name="winternotch" --baseurl="http://foreman.winternotch.com/pulp/repos/Default_Organization/Library/custom/Winternotch_Packages/Winternotch_Repo/"
at the end, make sure the bootstrap cloud-init filename you are copying is correct
cp /floppy/winternotch-cloud.cfg /mnt/sysimage/etc/cloud/cloud.cfg
(requires docker)
git clone https://github.com/jetbrains-infra/packer-builder-vsphere
cd packer-builder-vsphere
docker-compose run build
https://www.packer.io/docs/extending/plugins.html#installing-plugins
cd packer-builder-vsphere
mkdir -p $HOME/.packer.d/plugins
cp bin/*.macos $HOME/.packer.d/plugins
https://github.com/jetbrains-infra/packer-builder-vsphere/tree/master/examples/
centos8 : https://github.com/nelg/packer-builder-vsphere
centos7 : https://github.com/remijouannet/packer-builder-vsphere
# normal build
packer build hardened-centos7.json
# force continuation if artifacts exist
packer build -force hardened-centos7.json
# dont destroy vm on abort (to debug errors)
packer build -on-error=abort hardened-centos7.json
# debug logging
PACKER_LOG=1 packer build -force hardened-centos7.json
# step by step debugging
packer build -debug whardened-centos7.json