Last active
March 21, 2023 23:26
-
-
Save ruzickap/3258c16015d35495811a65b17626b94a to your computer and use it in GitHub Desktop.
Quick and Dirty script building Windows using Packer + Ansible + WinRM on QEMU (libvirt)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -x | |
mkdir test | |
cd test | |
curl https://raw.githubusercontent.com/ruzickap/packer-templates/master/http/windows-server-2016/Autounattend.xml | sed '/.*Microsoft-Windows-PnpCustomizationsWinPE.*/,/component>/d' > Autounattend.xml | |
wget -c https://raw.githubusercontent.com/ruzickap/packer-templates/master/scripts/win-common/fixnetwork.ps1 | |
test -f packer || ( wget https://releases.hashicorp.com/packer/1.2.0/packer_1.2.0_linux_amd64.zip && unzip packer_1.2.0_linux_amd64.zip && rm packer_1.2.0_linux_amd64.zip ) | |
cat > win.yml << EOF | |
--- | |
- hosts: all | |
gather_facts: true | |
tasks: | |
- debug: msg="Getting facts works fine..." | |
EOF | |
cat > windows-enterprise-eval.json << \EOF | |
{ | |
"builders": | |
[ | |
{ | |
"name": "windows-enterprise-eval", | |
"type": "qemu", | |
"iso_checksum_type": "sha256", | |
"iso_checksum": "1ce702a578a3cb1ac3d14873980838590f06d5b7101c5daaccbac9d73f1fb50f", | |
"iso_urls": [ "http://care.dlservice.microsoft.com/dl/download/1/4/9/149D5452-9B29-4274-B6B3-5361DBDA30BC/14393.0.161119-1705.RS1_REFRESH_SERVER_EVAL_X64FRE_EN-US.ISO" ], | |
"communicator": "winrm", | |
"winrm_username": "vagrant", | |
"winrm_password": "vagrant", | |
"winrm_timeout": "12h", | |
"winrm_use_ssl": "true", | |
"winrm_insecure": "true", | |
"disk_interface": "ide", | |
"net_device": "e1000", | |
"qemuargs": [[ "-display", "gtk" ], [ "-m", "4G" ], [ "-smp", "2" ]], | |
"disk_size": "51200", | |
"floppy_files": [ | |
"fixnetwork.ps1", | |
"Autounattend.xml" | |
] | |
} | |
], | |
"provisioners": [ | |
{ | |
"type": "ansible", | |
"user": "vagrant", | |
"playbook_file": "win.yml", | |
"extra_arguments": [ | |
"--connection", "packer", | |
"-vvv", | |
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None" | |
] | |
} | |
], | |
"post-processors": [ | |
[ | |
{ | |
"type": "vagrant", | |
"output": "windows-enterprise-eval-{{ .Provider }}.box" | |
} | |
] | |
] | |
} | |
EOF | |
mkdir connection_plugins | |
wget -c https://raw.githubusercontent.com/hashicorp/packer/master/test/fixtures/provisioner-ansible/connection_plugins/packer.py -P connection_plugins | |
rm -rf my-ansible | |
virtualenv my-ansible | |
. my-ansible/bin/activate | |
pip install pywinrm | |
for ANSIBLE in ansible==2.5.0b2 ; do | |
#ansible==2.4.0.0 ansible==2.4.1.0 ansible==2.4.2.0 ansible==2.4.3.0 ansible==2.5.0b2 git+https://github.com/ansible/ansible.git@devel | |
echo -e "\n\n*** $ANSIBLE\n\n" | |
pip install $ANSIBLE | |
virtualenv --relocatable my-ansible | |
ansible --version | |
TMPDIR="/var/tmp/" PACKER_LOG=1 PACKER_LOG_PATH="packerlog_`basename $ANSIBLE`" ./packer build ./windows-enterprise-eval.json | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment