Packer's
templates to create Microsoft Hyper-V virtual machines
Consider buying me a coffee if you like my work. All donations are appreciated. All donations will be used to pay for pipeline running costs
1.10.0
. Do not use packer below 1.7.0 version. For previous packer versions use previous releases from this repositorypacker
http server (look down below)2.3.4
- for vagrant
version of scripts. Boxes (prebuilt) are already available here: https://app.vagrantup.com/marcinbojkochoco install packer --version=1.10.0 -y
In root folder of a repository
packer init --upgrade config.pkr.hcl
Remove-NetFirewallRule -DisplayName "Packer_http_server" -Verbose
New-NetFirewallRule -DisplayName "Packer_http_server" -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8000-9000
To adjust to your Hyper-V, please check variables below and/or in ./variables files
vlan_id
in /variables/variables.*.pkvars.hcl) - proper VLAN ID . Look up to find your build server vEthernet setings.switch_name
in /variables/variables.*.pkvars.hcl) - proper Hyper-V Virtual Switch name (access to Internet will be required). Make sure you're using pre-existing switch in your Hyper-V server - creation of new switch by packer, instead of reusing existing one can cause lack of Internet access, thus failing the build.# example of mentioned variables
vlan_id = ""
switch_name = "vSwitch"
OS | username | password |
---|---|---|
Windows | Administrator | password |
CentOS/RHEL | root | password |
Ubuntu | ubuntu | password |
packages from a list below:
Package | Version | Mandatory/Optional |
---|---|---|
dotnetfx | latest | Mandatory |
sysinternals | latest | Mandatory |
tabby | latest | Optional |
Repositories:
Repository | Package | switch | default |
---|---|---|---|
Epel 7/8/9 | epel-release | can be switched off by setting "install_epel" to false |
true |
Webmin | webmin | can be switched on by setting "install_webmin" to false |
false |
Cockpit | cockpit | can be switched on by setting "install_zabbix" to true |
true |
Hyper-V | SCVMM Agent | can be switched off by setting "install_hyperv" to false |
true |
Neofetch | neofetch | can be switched off by setting "install_neofetch" to false |
true |
Be aware, turning off latest System Center Virtual Machine Agent will cause System Center fail to deploy machines
During deployment ansible-base and ansible are installed in operating system. After deployment ends, these packages are removed.
Playbooks are held in /extra/playbooks
folder, with proper OS variables.
./variables/*.yml
files to achieve override for ansibleinstall_epel: true # install Epel
install_webmin: true # install Webmin
install_hyperv: true # install Hyper-v and scvmm agent
install_cockpit: false # install Cockpit
install_docker_workaround: true # add `fsck.repair=yes` to grub
install_neofetch: true # install neofetch
install_updates: true # install updates
install_extra_groups: true # install extra groups
docker_prepare: false # prepare extra volumen for docker
extra_device: "" # prepare mkfs and mount extra block device for docker
install_motd: true # install motd (neofetch run)
Building machines is realised through a dedicated script hv_generic.ps1
with proper parameters.
hv_generic.ps1
parametersFor Generation 2 prepare secondary.iso
with folder structure:
- ./extra/files/windows/2022/std/Autounattend.xml => /Autounattend.xml
- ./extra/scripts/hyper-v/bootstrap.ps1 => /bootstrap.ps1
This template uses this image name in Autounattendes.xml. If youre using different ISO you'll have to adjust that part in proper file and rebuild secondary.iso
image.
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/NAME </Key>
<Value>Windows Server 2022 SERVERSTANDARD</Value>
</MetaData>
</InstallFrom>
Action | Version | Template | Log | OS |
---|---|---|---|---|
build |
windows_server_2019_std | windows | 0/1 | Microsoft Server 2019 Standard |
build |
windows_server_2019_dc | windows | 0/1 | Microsoft Server 2019 Datacenter |
build |
windows_server_2022_std | windows | 0/1 | Microsoft Server 2022 Standard |
build |
windows_server_2022_dc | windows | 0/1 | Microsoft Server 2022 Datacenter |
Example for Windows 2019 Standard
```powershell
./hv_generic.ps1 -Action build -Version windows_server_2019_std -Template windows -Log 0
Example for Windows 2019 Datacenter
./hv_generic.ps1 -Action build -Version windows_server_2019_dc -Template windows -Log 0
Example for Windows 2022 Standard
./hv_generic.ps1 -Action build -Version windows_server_2022_std -Template windows -Log 0
Example for Windows 2022 Datacenter
./hv_generic.ps1 -Action build -Version windows_server_2022_dc -Template windows -Log 0
Action | Version | Template | Log | OS |
---|---|---|---|---|
build |
almalinux-8.9 | rhel | 0/1 | Alma Linux 8.9 |
build |
almalinux-9.4 | rhel | 0/1 | Alma Linux 9.4 |
.\hv_generic.ps1 -Action build -Version almalinux-8.9 -Template rhel -Log 0
.\hv_generic.ps1 -Action build -Version almalinux-9.4 -Template rhel -Log 0
Action | Version | Template | Log | OS |
---|---|---|---|---|
build |
rockylinux-8.9 | rhel | 0/1 | Rocky Linux 8.9 |
build |
rockyinux-9.4 | rhel | 0/1 | Rocky Linux 9.4 |
.\hv_generic.ps1 -Action build -Version rockylinux-8.9 -Template rhel -Log 0
.\hv_generic.ps1 -Action build -Version rockylinux-9.4 -Template rhel -Log 0
Action | Version | Template | Log | OS |
---|---|---|---|---|
build |
oraclelinux-8.9 | rhel | 0/1 | Oracle Linux 8.9 |
build |
oraclelinux-9.4 | rhel | 0/1 | Oracle Linux 9.4 |
.\hv_generic.ps1 -Action build -Version oraclelinux-8.9 -Template rhel -Log 0
.\hv_generic.ps1 -Action build -Version oraclelinux-9.4 -Template rhel -Log 0
Action | Version | Template | Log | OS |
---|---|---|---|---|
build |
ubuntu-20.04 | ubuntu | 0/1 | Ubuntu 20.04 |
build |
ubuntu-22.04 | ubuntu | 0/1 | Ubuntu 22.04 |
build |
ubuntu-24.04 | ubuntu | 0/1 | Ubuntu 24.04 |
.\hv_generic.ps1 -Action build -Version ubuntu-20.04 -Template ubuntu -Log 0
.\hv_generic.ps1 -Action build -Version ubuntu-22.04 -Template ubuntu -Log 0
.\hv_generic.ps1 -Action build -Version ubuntu-24.04 -Template ubuntu -Log 0
Please create an issue in github. There is slim chance I'll find the time to be your personal helpdesk ;)
Sure. If I can ask - create your PR in smaller sizes, this is repo used for my work, so smaller changes - bigger chances to succeed.
During the deployment secure keys are stored in *.vmcx
file and are separated from *.vhdx
file. To countermeasure it - there is added extra step in a form of (/usr/local/bin/uefi.sh
) script that will check for existence of CentOS folder in EFI and will add extra entry in UEFI.
In manual setup you can run it as a part of your deploy. In SCVMM deployment I'd recommend using RunOnce
feature.
https://github.com/hashicorp/packer/issues/7278#issuecomment-468492880
Fixed in version 1.4.4. Do not use previous versions
Fixed in version 1.4.4. Do not use lower versions
No resolution so far, template needs to be changed to pass real IP address, or there should be connection between these addresses. Limiting these, end with timeout errors.**
windows-restart
provisionerhttps://github.com/hashicorp/packer/issues/6733
https://github.com/hashicorp/packer/issues/5023 Will be fixed in 1.4.x revision
You can use number. If you have 4 images on the list of choice - use ImageIndex
with proper Value
<ImageInstall>
<OSImage>
<InstallFrom>
<MetaData wcm:action="add">
<Key>/IMAGE/INDEX </Key>
<Value>2</Value>
</MetaData>
</InstallFrom>
<InstallTo>
<DiskID>0</DiskID>
<PartitionID>2</PartitionID>
</InstallTo>
</OSImage>
</ImageInstall>
Increase variable update_timeout
in ./variables/*.json
file - this will create longer pauses between stages, allowing cycles to complete before jumping to another one.
I wish. In short - Windows. These builds should be done with minimum effort (Hyper-V role is enough). Building custom ansible station with lots of checks right now fails in my tryouts.
Consider buying me a coffee if you like my work. All donations are appreciated. All donations will be used to pay for pipeline running costs
Work based on https://github.com/jacqinthebox/packer-templates.git