This repo contains code that can generate Vagrant boxes. The overall goal is to cover supported Windows Server OS'.
Each image is designed to be;
pwsh
(formally known as PowerShell Core) on all host types except for Server 2012The blog post Using Packer to Create Windows Images contain a more detailed guide on this process and how it all works.
The contents there are outdated as Packer
is no longer used but the generic concepts still apply here.
Feel free to read through it if you want to understand each component and how they fit together more.
Note: This repo used to use Packer to build the Vagrant images (hence the name) but no longer does.
To use the scripts in this repo you will need the following;
mkisofs
to build the bootstrapping iso for Windowspigz
to compress the resulting Vagrant box imageThe following Python libraries are also used:
One of the following hypervisers as defined by platform
:
To install mkisofs
and pigz
, you can run one of the commands below depending on your distribution;
# for Debian/Ubuntu
sudo apt-get install mkisofs pigz
# for RHEL/CentOS
sudo yum install mkisofs pigz
# for Fedora
sudo dnf install genisoimage pigz
# for MacOS (requires Homebrew)
brew install cdrtools pigz
The Ansible requirements can be installed with
pip install -r requirements.txt
ansible-galaxy role install -r requirements.yml -p roles
ansible-galaxy collection install -r requirements.yml -p collections
The imaging process uses Ansible from start to finish and in most cases can be rerun for it to take off where it started. To start the process run the following script:
ansible-playbook main.yml --limit '*2022'
This will build the Windows Server 2022 image for QEMU.
You can change *2022
to the Windows version as defined in inventory.yml that you wish to build (the *
is important).
The following options can also be specified with -e
to change the build behaviour:
platform
: The Hypervisor to build for - can be qemu
, virtualbox
, or hyperv
(default: qemu
).headless
: Dont't display the VM console during the build process (default: true
)output_dir
: The base directory to store the output/build files (default: {{ playbook_dir }}/output
).setup_username
: The name of the user to create on the base imagesetup_password
: The password to apply to the username that is created.iso_src_<host>
: The URL or path to use for the install ISO, change <host>
to the inventory hostname, e.g. 2022
, or 2019
.iso_checksum_<host>
: The checksum for iso_src
, change <host>
to the inventory hostname, e.g. 2022
, or 2019
.iso_wim_label_<host>
: The Windows install WIM label to install, change <host>
to the inventory hostname, e.g. 2022
, or 2019
.It is technically possible to build more than 1 image at a time by specifying multiple hosts with --limit
but it is recommended to kick off the runs in parallel to keep better track.
After running the image process will have created a few files in {{ output_dir }}/{{ host }}
:
description.md
: A markdown description of the box created.{{ platform }}.box
: The box for the specific platform hypervisor.Because Ansible cannot run natively on Windows the Hyper-V builder must be run on WSL.
The current process has been tested on WSL2 and will probably not work for WSL1.
Before kicking off the run on WSL you must ensure that you've started the WSL process as an administrator so it has access to manage Hyper-V VMs.
You also need to either run this repo from a Windows path or specify -e output_dir=/mnt/c/some/path
so that Hyper-V can access the build artifacts.
Here is a brief step by step overview of what actually happens with the images
Autounattend.xml
file generated by Ansiblevagrant
user and run the bootstrap.ps1
scriptFrom this point Ansible will create an image of the OS which can be used by Vagrant. When Vagrant first starts up the image, it will automatically log on and, rearm the activation key and recreate the WinRM listeners.