The syntax "sudo ifconfig up eth1" was throwing an error in the current version of Ubuntu. The "up" option needs to come after the interface name for it to work.
Building DetectionLab on ESXi
NOTE: This is an early release and it's possible that certain features may not work perfectly for everyone yet
Prereqs (~30-60 minutes)
- Have an ESXi instance version 6 or higher. VSphere is NOT required.
- Install the requirements from the ESXi Terraform Provider
- If building on MacOS, don't forget to change the GOOS from linux to darwin!
GOOS=linux->GOOS=darwin
- If building on MacOS, don't forget to change the GOOS from linux to darwin!
- Build and install the terraform-provider-esxi provider
- Your ESXi must have at least two separate networks - one that is accessible from your current machine (VM Network) and a HostOnly network to allow the VMs to have internet access (HostOnly).
- OVFTool must be installed and in your path.
- On MacOS, I solved this by creating a symbolic link to the ovftool included in VMWare Fusion:
sudo ln -s "/Applications/VMware Fusion.app/Contents/Library/VMware OVF Tool/ovftool" "/usr/local/bin/ovftool"
- On MacOS, I solved this by creating a symbolic link to the ovftool included in VMWare Fusion:
- On your ESXI, you must:
- Enable SSH
- Enable the "Guest IP Hack"
- Open VNC ports on the firewall
- Instructions for those steps are here: https://nickcharlton.net/posts/using-packer-esxi-6.html
- Install Ansible
Steps
-
(5 Minutes) Edit the variables in
DetectionLab/ESXi/Packer/variables.jsonto match your ESXi configuration. Theesxi_network_with_dhcp_and_internetvariable refers to any ESXi network that will be able to provide DHCP and internet access to the VM while it's being built in Packer. -
(45 Minutes) From the
DetectionLab/ESXi/Packerdirectory, run:
PACKER_CACHE_DIR=../../Packer/packer_cache packer build -var-file variables.json windows_10_esxi.jsonPACKER_CACHE_DIR=../../Packer/packer_cache packer build -var-file variables.json windows_2016_esxi.jsonPACKER_CACHE_DIR=../../Packer/packer_cache packer build -var-file variables.json ubuntu1804_esxi.json
These commands can be run in parallel from three separate terminal sessions.
- (1 Minute) Once the Packer builds finish, verify that you now see Windows10, WindowsServer2016, and Ubuntu1804 in your ESXi console

- (5 Minutes) Edit the variables in
ESXi/variables.tfto match your local ESXi configuration or create a terraform.tfvars file (RECOMMENDED) to override them. - (25 Minutes) From
DetectionLab/ESXi, runterraform init && terraform apply - Once Terraform has finished bringing the hosts online, change your directory to
DetectionLab/ESXi/Ansible - (1 Minute) Edit
DetectionLab/ESXi/Ansible/inventory.ymland replace the IP Addresses with the respective IP Addresses of your ESXi VMs. These IP addresses much be reachable from your host machine! - (3 Minute)s Edit
DetectionLab/ESXi/resources/01-netcfg.yaml. These are the IP addresses that will be applied to the logger network interfaces. These should be be able to be found in your ESXi console or from the Terraform outputs. - (3 Minute) Before running any Ansible playbooks, I highly recommend taking snapshots of all your VMs! If anything goes wrong with provisioning, you can simply restore the snapshot and easily debug the issue.
- Change your directory to
DetectionLab/ESXi/Ansible - (30 Minutes) Run
ansible-playbook -vvv detectionlab.yml - If all goes well, you should see the following and your lab is complete!

If you run into any issues along the way, please open an issue on Github and I'll do my best to find a solution.
Future work required
- It probably makes sense to abstract all of the logic in
bootstrap.shinto individual Ansible tasks - There's a lot of areas to make reliability improvements
- I'm guessing there's a way to parallelize some of this execution: https://medium.com/developer-space/parallel-playbook-execution-in-ansible-30799ccda4e0
Debugging / Troubleshooting
- If an Ansible playbook fails, you can pick up where it left off with
ansible-playbook -vvv detectionlab.yml --start-at-task="taskname"
Credits
As usual, this work is based off the heavy lifting that others have done. My primary sources for this work were:
- Josenk's Terraform-ESXI-Provider - Without this, there would be no way to deploy DL to ESXi without paying for VSphere. Send him/her some love 💌
- Automate Windows VM Creation and Configuration in vSphere Using Packer, Terraform and Ansible - Dmitry Teslya
- Building Virtual Machines with Packer on ESXi 6 - Nick Charlton
- The DetectionLab work that juju4 has been doing on Azure and Ansible
- lofi hip hop radio - beats to relax/study to 🔉
Thank you to all of the sponsors who made this possible!

