This repository uses Packer to build a virtual machines for VMware, VirtualBox, or AWS AMI.
- ๐ค - A "thinker" icon means that a little extra thinking may be required. Perhaps there are some choices to be made. Perhaps it's an optional step.
- โ๏ธ - A "pencil" icon means that the instructions may need modification before performing.
โ ๏ธ - A "warning" icon means that something tricky is happening, so pay attention.
- Space: This repository and demonstration require 6 GB free disk space.
- Time: Budget 2 hours minutes to create the virtual machine.
- Background knowledge: This repository assumes a working knowledge of:
The following software programs need to be installed:
For more information on environment variables, see Environment Variables.
-
Set these environment variable values:
export GIT_ACCOUNT=senzing export GIT_REPOSITORY=packer-ansible export GIT_ACCOUNT_DIR=~/${GIT_ACCOUNT}.git export GIT_REPOSITORY_DIR="${GIT_ACCOUNT_DIR}/${GIT_REPOSITORY}"
-
Follow steps in clone-repository to install the Git repository.
๐ค The Makefile
uses the following files to create virtual images:
TEMPLATE_FILE
- The Packertemplate.json
file used in the build.PLATFORM_VAR_FILE
- A file of variables specifying a base image (ISO, AMI, etc.)CUSTOM_VAR_FILE
- A user-configurable file specifying values to use during the build.
In the examples below, the CUSTOM_VAR_FILE
is set to vars/custom-var.json
In practice, this value should be modified to point to a user's custom file of variables.
The CUSTOM_VAR_FILE
, can be used to:
- Specify an Ansible playbook.
- Add Multifactor Authentication information
- Specify SSH keys
- Change disk or memory size
- Specify an AMI Marketplace Image
Example:
export CUSTOM_VAR_FILE=~/my-vars/my-custom-var.json
โ๏ธ Packer cache the downloaded images into a folder called packer_cache. By default, the packer_cache folder is created in the packer-ansible folder. To modify the location of the packer cache folder, simply export the following variable:
Example:
export PACKER_CACHE_DIR=/path/to/packer_cache
โ๏ธ The Ansible installation on the image can be adjusted with the following modes:
install
- The Ansible package is installed, used and remains on the image.ephemeral
- The Ansible package is installed, used and then removed from the image.none
- The Ansible package is never installed on the image (default).
Example:
export ANSIBLE_MODE=install
Example: amazon-ebs (Before creating AMIs, go through the AWS AMI setup first)
cd ${GIT_REPOSITORY_DIR}
export TEMPLATE_FILE=template-centos.json
export PLATFORM_VAR_FILE=vars/centos-07.06.json
export CUSTOM_VAR_FILE=vars/custom-var.json
make amazon-ebs
To build GCP Compute Images (Before creating images, go through the GCP Compute Image setup first), instead of make amazon-ebs
, run the following:
make googlecompute
To build virtualbox, instead of make amazon-ebs
, run the following:
make virtualbox-iso
To build vmware-iso, instead of make amazon-ebs
, run the following:
make vmware-iso
Example: amazon-ebs
cd ${GIT_REPOSITORY_DIR}
export TEMPLATE_FILE=template-centos.json
export PLATFORM_VAR_FILE=vars/centos-08.02.json
export CUSTOM_VAR_FILE=vars/custom-var.json
make amazon-ebs
To build GCP Compute Images (Before creating images, go through the GCP Compute Image setup first), instead of make amazon-ebs
, run the following:
make googlecompute
To build virtualbox, instead of make amazon-ebs
, run the following:
make virtualbox-iso
To build vmware-iso, instead of make amazon-ebs
, run the following:
make vmware-iso
Example: amazon-ebs
cd ${GIT_REPOSITORY_DIR}
export TEMPLATE_FILE=template-debian.json
export PLATFORM_VAR_FILE=vars/debian-09.12.00.json
export CUSTOM_VAR_FILE=vars/custom-var.json
make amazon-ebs
To build GCP Compute Images (Before creating images, go through the GCP Compute Image setup first), instead of make amazon-ebs
, run the following:
make googlecompute
To build virtualbox, instead of make amazon-ebs
, run the following:
make virtualbox-iso
To build vmware-iso, instead of make amazon-ebs
, run the following:
make vmware-iso
Example: amazon-ebs
cd ${GIT_REPOSITORY_DIR}
export TEMPLATE_FILE=template-debian.json
export PLATFORM_VAR_FILE=vars/debian-10.04.00.json
export CUSTOM_VAR_FILE=vars/custom-var.json
make amazon-ebs
To build GCP Compute Images (Before creating images, go through the GCP Compute Image setup first), instead of make amazon-ebs
, run the following:
make googlecompute
To build virtualbox, instead of make amazon-ebs
, run the following:
make virtualbox-iso
To build vmware-iso, instead of make amazon-ebs
, run the following:
make vmware-iso
Example: amazon-ebs
cd ${GIT_REPOSITORY_DIR}
export TEMPLATE_FILE=template-ubuntu.json
export PLATFORM_VAR_FILE=vars/ubuntu-18.04.04.json
export CUSTOM_VAR_FILE=vars/custom-var.json
make amazon-ebs
To build GCP Compute Images (Before creating images, go through the GCP Compute Image setup first), instead of make amazon-ebs
, run the following:
make googlecompute
To build virtualbox, instead of make amazon-ebs
, run the following:
make virtualbox-iso
To build vmware-iso, instead of make amazon-ebs
, run the following:
make vmware-iso
- Choose VMX file
- VMware Workstation > File > Open...
- Navigate to
.../output-vmware-iso-nnnnnnnnnn/
- Choose
senzing-packer-xxxxxx-nnnnnnnnnn.vmx
- Navigate to
- VMware Workstation > File > Open...
- Optional: Change networking
- Navigate to VMware Workstation > My Computer > senzing-packer-xxxxx-nnnnnnnnnn
- Right click on "senzing-packer-xxxxxx-nnnnnnnnnn" and choose "Settings"
- Choose "Network Adapter" > "Network Connection" > ๐ Bridged: Connected directly to the physical network
- Click "Save"
- Run image
- Choose VMware Workstation > My Computer > senzing-packer-xxxxx-nnnnnnnnnn
- Click "Start up this guest operating system"
- Username: vagrant Password: vagrant
-
โ๏ธ Identify virtual image metadata. Example:
export VAGRANT_NAME=packer-xxxxxx-virtualbox export VIRTUALBOX_FILE=./senzing-packer-xxxxxx-virtualbox-nnnnnnnnnn.box
-
Add VirtualBox image to
vagrant
Example:vagrant box add --name=${VAGRANT_NAME} ${VIRTUALBOX_FILE}
An example of how to run in a new directory.
In this example the /tmp/packer-ubuntu-18.04
directory is used.
export VAGRANT_DIR=/tmp/${VAGRANT_NAME}
Back up an old directory and initialize new directory with Vagrant image.
mv ${VAGRANT_DIR} ${VAGRANT_DIR}.$(date +%s)
mkdir ${VAGRANT_DIR}
cd ${VAGRANT_DIR}
vagrant init ${VAGRANT_NAME}
Modify Vagrantfile to allow remote login by
uncommenting config.vm.network
in ${VAGRANT_DIR}/Vagrantfile
.
Example:
sed -i.$(date +'%s') \
-e 's/# config.vm.network \"public_network\"/config.vm.network \"public_network\"/g' \
${VAGRANT_DIR}/Vagrantfile
cd ${VAGRANT_DIR}
vagrant up
cd ${VAGRANT_DIR}
vagrant ssh
In the vagrant machine, find the IP address.
ip addr show
SSH login from a remote machine.
Password: vagrant
To remove Vagrant image, on host machine:
vagrant box remove ${VAGRANT_NAME}
If the following error surfaces
Build 'vmware-iso' errored: Error detecting host IP: Could not find vmnetdhcp conf file:
To resolve the error, include the following in the template's vmware-iso builder,
"network": "vmnet8"