This project can be used to create ad-hoc Windows labs. The included sample configurations create 3 virtual machines running Windows Server 2016 (2 domain controllers and a file server), but you can easily customize and extend it. Project workflow consists of three stages:
- creation of Windows VM templates
- deployment of VMs out of those templates
- applying OS configurations It uses Packer Builder for VMware vSphere by JetBrains, Terraform and Ansible. VMware vSphere serves as a virtualization platform.
- Packer
- Packer Builder for VMware vSphere
- Terraform
- Ansible
- pywinrm module (
pip install pywinrm) - vSphere vCenter accessible from your workstation
- DHCP server for VM template building
- Windows Server 2016 ISO
- Clone this repo to your workstation (git clone https://github.com/dteslya/win-iac-lab)
- Make sure Packer, Terraform and Ansible binaries are all in PATH
- Download Packer Builder plugin from Releases and place it in
packerdir - Remove
.exampleextension from all the configuration files and adjust the variables according to your environment
Packer setup consists of 3 main components:
windows-server-2016.jsonvars.jsonsetupdir containing files necessary for automatic Windows installation
windows-server-2016.json describes the connection parameters for vSphere, VM hardware including paths to Windows ISO and vmtools, and which files to put on virtual floppy drive. Those files are:
autounattend.xmlwindows setup answer filesetup.ps1powershell script which enables WinRM access for packervmtools.cmdbatch file which installs vmware tools
vars.json file contains all the values of the variables defined in windows-server-2016.json, including vSphere user and password. These two variables are marked as sensitive in windows-server-2016.json so that Packer doesn't reveal them during its run.
I tend to use one .tf file per VM for better readability.
01-PDC.tfPrimary Domain Controller VM02-ReplicaDC.tfReplica Domain Controller VM03-FileServer.tfFile Server VMbase.tfvCenter connection parametersvariables.tfall variables are defined hereterraform.tfvarsvariables' values (I keep this file in .gitignore)
I put 3 plays in one playbook: each for every server role.
winlab.ymlplaybookinventory.ymlall the hosts are defined hereansible.cfgansible reads this file by default to find inventory and vault password filesgroupvars/all.ymlall variables are defined here. I use Ansible Vault to encrypt sensitive data such as passwords (ansible-vault encrypt_string string_to_encrypt)
- cd to
packerdir - run
packer build -var-file=vars.json windows-server-2016.json
- cd to
terraformdir - run
terraform init - run
terraform plan - run
terraform apply
- cd to
ansibledir - run
ansible-playbook winlab.yml
This project was initially inspired by SDBrett's MCSA Lab