Skip to content

Commit

Permalink
my_windows-10 added, build.sh simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzickap committed Mar 15, 2018
1 parent db89de3 commit 73226ac
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 104 deletions.
4 changes: 2 additions & 2 deletions ansible/site.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- hosts: all
become: yes

roles:
- ansible-role-my_common_defaults
- { role: ansible-role-virtio-win, virtio_win_iso_path: 'E:\\', when: ansible_system == 'Win32NT' and ansible_system_vendor == 'QEMU' }
- { role: ansible-role-my_common_defaults, when: packer_build_name | regex_search('^my_') }
20 changes: 5 additions & 15 deletions ansible/win.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
---
- hosts: all

vars:
ntp_server: pool.ntp.org

roles:
- role: ansible-role-virtio-win
virtio_win_iso_path: 'E:\\'
when: ansible_system_vendor == "QEMU"

tasks:
- name: Start NTP service (w32time)
win_service:
name: w32time
state: started

- name: Configure NTP
win_command: w32tm /config /manualpeerlist:"{{ ntp_server }}" /reliable:yes /update

- name: Enable Remote Desktop
win_regedit:
key: 'HKLM:\System\CurrentControlSet\Control\Terminal Server'
Expand All @@ -41,7 +30,8 @@
account_disabled: no
when: ansible_distribution | search("Microsoft Windows 10")

# Windows Updates is not working in ansible-2.4.0.0-1.fc27 and latest Ansible 2.4.2 is not working at all with Packer + WinRM
# That's the reason why updates are disabled for now...
# - name: Install windows updates
# win_updates:
# Windows Updates is not working in ansible-2.4.0.0-1.fc27 and latest Ansible 2.4.2 is not working at all with Packer + WinRM
# That's the reason why updates are disabled for now...
#- name: Install windows updates
# win_updates:

140 changes: 64 additions & 76 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export PACKER_CACHE_DIR="$TMPDIR"
export VIRTIO_WIN_ISO_URL="https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso"
export VIRTIO_WIN_ISO=$(basename $VIRTIO_WIN_ISO_URL)
export LOG_DIR="$TMPDIR"
export HEADLESS=${HEADLESS:-true}
export PACKER_BINARY="packerio"

readonly PROGNAME=$(basename $0)
readonly ARGS="$@"
Expand All @@ -20,9 +22,10 @@ This script can build the various libvirt and virtualbox images.
You should have Packer, Ansible, libvirt and VirtualBox installed.
List of all supported builds:
* windows_10 (libvirt, virtualbox)
* windows_2016 (libvirt, virtualbox)
* windows_2012_r2 (libvirt, virtualbox)
* my_windows-10 (libvirt, virtualbox)
* windows-10 (libvirt, virtualbox)
* windows-2016 (libvirt, virtualbox)
* windows-2012_r2 (libvirt, virtualbox)
* ubuntu-desktop-17.10 (libvirt)
* ubuntu-server-16.04 (libvirt)
* ubuntu-server-14.04 (libvirt)
Expand All @@ -33,46 +36,93 @@ List of all supported builds:
Examples:
Build Windows 10 Enterprise Evaluation, Windows Server 2016 Evaluation and Windows Server 2012 Evaluation for Virtualbox:
$PROGNAME windows_10:virtualbox windows_2016:virtualbox windows_2012_r2:virtualbox
$PROGNAME my_windows-10:virtualbox windows-10:virtualbox windows-2016:virtualbox windows-2012_r2:virtualbox
Build Windows 10 Enterprise Evaluation, Windows Server 2016 Evaluation and Windows Server 2012 Evaluation for libvirt:
$PROGNAME windows_10:libvirt windows_2016:libvirt windows_2012_r2:libvirt
$PROGNAME my_windows-10:libvirt windows-10:libvirt windows-2016:libvirt windows-2012_r2:libvirt
Build Ubuntu Desktop 17.10, Ubuntu Server 16.04, 14.04, My Ubuntu Server 16.04, 14.04 and My Centos 7 for libvirt:
Build Ubuntu Desktop 17.10, Ubuntu Server 16.04, 14.04, My Ubuntu Server 16.04, 14.04 and My CentOS 7 for libvirt:
$PROGNAME ubuntu-desktop-17.10:libvirt ubuntu-server-16.04:libvirt ubuntu-server-14.04:libvirt my_ubuntu-server-16.04:libvirt my_ubuntu-server-14.04:libvirt my_centos-7:libvirt
EOF
}

cmdline() {
BUILDS=$@

if [ -z $BUILDS ]; then
if [ -z "$BUILDS" ]; then
usage
exit 0;
fi

for BUILD in $BUILDS; do
export PACKER_VAGRANT_PROVIDER="${BUILD##*:}"
export MYBUILD="${BUILD%:*}"
export MY_NAME=`echo $MYBUILD | awk -F '-' '{ print $1 }'`

echo "*** $MYBUILD - $PACKER_VAGRANT_PROVIDER"

case $MYBUILD in
*centos*)
export MY_NAME=`echo $MYBUILD | awk -F '-' '{ print $1 }'`
export CENTOS_VERSION=`echo $MYBUILD | awk -F '-' '{ print $2 }'`
eval centos
export CENTOS_TAG=`curl -s ftp://ftp.cvut.cz/centos/$CENTOS_VERSION/isos/x86_64/sha1sum.txt | sed -n 's/.*-\(..\)\(..\)\.iso/\1\2/p' | head -1`
export CENTOS_ARCH="x86_64"
export CENTOS_TYPE="NetInstall"
export NAME="${MY_NAME}-${CENTOS_VERSION}-${CENTOS_ARCH}"

sudo dnf upgrade -y ansible

packer_build ${MY_NAME}-${CENTOS_VERSION}.json
;;
*ubuntu*)
export MY_NAME=`echo $MYBUILD | awk -F '-' '{ print $1 }'`
export UBUNTU_TYPE=`echo $MYBUILD | awk -F '-' '{ print $2 }'`
export UBUNTU_MAJOR_VERSION=`echo $MYBUILD | awk -F '-' '{ print $3 }'`
eval ubuntu
export UBUNTU_ARCH="amd64"
export UBUNTU_VERSION=`curl -s http://releases.ubuntu.com/${UBUNTU_MAJOR_VERSION}/SHA1SUMS | sed -n "s/.*ubuntu-\([^-]*\)-${UBUNTU_TYPE}-${UBUNTU_ARCH}.iso/\1/p" | head -1`
export NAME="${MY_NAME}-${UBUNTU_VERSION::5}-${UBUNTU_TYPE}-${UBUNTU_ARCH}"

sudo dnf upgrade -y ansible

packer_build ${MY_NAME}-${UBUNTU_TYPE}.json
;;
*windows-10*)
export WINDOWS_VERSION="10"
export WINDOWS_ARCH="x64"
export WINDOWS_EDITION="enterprise"
export NAME="${MY_NAME}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"

# Do no use latest ansible 2.4.2 for now (Gathering Facts is not working properly on Windows + WinRM)
sudo dnf install -y ansible-2.4.0.0-1.fc27

packer_build ${MY_NAME}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-eval.json
;;
windows*)
eval ${MYBUILD}
*windows-2016*)
export WINDOWS_VERSION="2016"
export WINDOWS_ARCH="x64"
export WINDOWS_TYPE="server"
export WINDOWS_EDITION="standard"
export NAME="${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"

# Do no use latest ansible 2.4.2 for now (Gathering Facts is not working properly on Windows + WinRM)
sudo dnf install -y ansible-2.4.0.0-1.fc27

packer_build ${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.json
;;
*windows-2012_r2*)
export WINDOWS_VERSION="2012"
export WINDOWS_RELEASE="r2"
export WINDOWS_ARCH="x64"
export WINDOWS_TYPE="server"
export WINDOWS_EDITION="standard"
export NAME="${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-${WINDOWS_RELEASE}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"

# Do no use latest ansible 2.4.2 for now (Gathering Facts is not working properly on Windows + WinRM)
sudo dnf install -y ansible-2.4.0.0-1.fc27

packer_build ${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.json
;;

esac
done
}
Expand All @@ -97,69 +147,7 @@ packer_build() {
esac

echo -e "\n\n*** $NAME [$PACKER_FILE] [$PACKER_BUILDER_TYPE]\n"
packerio build -only="$PACKER_BUILDER_TYPE" -color=false -var 'headless=true' $PACKER_FILE | tee "${LOG_DIR}/${NAME}-${PACKER_BUILDER_TYPE}-packer.log"
}

# Expected enviroments: UBUNTU_TYPE="desktop" UBUNTU_MAJOR_VERSION="17.10" MY_NAME="ubuntu"
ubuntu() {
export UBUNTU_ARCH="amd64"
export UBUNTU_VERSION=`curl -s http://releases.ubuntu.com/${UBUNTU_MAJOR_VERSION}/SHA1SUMS | sed -n "s/.*ubuntu-\([^-]*\)-${UBUNTU_TYPE}-${UBUNTU_ARCH}.iso/\1/p" | head -1`
export NAME="${MY_NAME}-${UBUNTU_VERSION::5}-${UBUNTU_TYPE}-${UBUNTU_ARCH}"

sudo dnf upgrade -y ansible

packer_build ${MY_NAME}-${UBUNTU_TYPE}.json
}

# Expected enviroments: CENTOS_VERSION="7" MY_NAME="ubuntu"
centos() {
export CENTOS_TAG=`curl -s ftp://ftp.cvut.cz/centos/$CENTOS_VERSION/isos/x86_64/sha1sum.txt | sed -n 's/.*-\(..\)\(..\)\.iso/\1\2/p' | head -1`
export CENTOS_ARCH="x86_64"
export CENTOS_TYPE="NetInstall"
export NAME="${MY_NAME}-${CENTOS_VERSION}-${CENTOS_ARCH}"

sudo dnf upgrade -y ansible

packer_build my_centos-${CENTOS_VERSION}.json
}

windows_2012_r2() {
export WINDOWS_VERSION="2012"
export WINDOWS_RELEASE="r2"
export WINDOWS_ARCH="x64"
export WINDOWS_TYPE="server"
export WINDOWS_EDITION="standard"
export NAME="windows-${WINDOWS_TYPE}-${WINDOWS_VERSION}-${WINDOWS_RELEASE}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"

# Do no use latest ansible 2.4.2 for now (Gathering Facts is not working properly on Windows + WinRM)
sudo dnf install -y ansible-2.4.0.0-1.fc27

packer_build windows-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.json
}

windows_2016() {
export WINDOWS_VERSION="2016"
export WINDOWS_ARCH="x64"
export WINDOWS_TYPE="server"
export WINDOWS_EDITION="standard"
export NAME="windows-${WINDOWS_TYPE}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"

# Do no use latest ansible 2.4.2 for now (Gathering Facts is not working properly on Windows + WinRM)
sudo dnf install -y ansible-2.4.0.0-1.fc27

packer_build windows-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.json
}

windows_10() {
export WINDOWS_VERSION="10"
export WINDOWS_ARCH="x64"
export WINDOWS_EDITION="enterprise"
export NAME="windows-${WINDOWS_VERSION}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"

# Do no use latest ansible 2.4.2 for now (Gathering Facts is not working properly on Windows + WinRM)
sudo dnf install -y ansible-2.4.0.0-1.fc27

packer_build windows-${WINDOWS_VERSION}-${WINDOWS_EDITION}-eval.json
$PACKER_BINARY build -only="$PACKER_BUILDER_TYPE" -color=false -var "headless=$HEADLESS" $PACKER_FILE 2>&1 | tee "${LOG_DIR}/${NAME}-${PACKER_BUILDER_TYPE}-packer.log"
}


Expand Down
2 changes: 1 addition & 1 deletion my_centos-7.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{
"type": "ansible",
"user": "vagrant",
"ansible_env_vars": [ "ANSIBLE_SSH_ARGS='-o ForwardAgent=no -o ControlMaster=auto -o ControlPersist=1h'" ],
"ansible_env_vars": [ "ANSIBLE_SSH_ARGS='-o ForwardAgent=no -o ControlMaster=auto -o ControlPersist=1h'", "become=true" ],
"playbook_file": "ansible/site.yml",
"sftp_command": "/usr/libexec/openssh/sftp-server -e"
},
Expand Down
2 changes: 1 addition & 1 deletion my_ubuntu-server.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{
"type": "ansible",
"user": "vagrant",
"ansible_env_vars": [ "ANSIBLE_SSH_ARGS='-o ForwardAgent=no -o ControlMaster=auto -o ControlPersist=1h'" ],
"ansible_env_vars": [ "ANSIBLE_SSH_ARGS='-o ForwardAgent=no -o ControlMaster=auto -o ControlPersist=1h'", "become=true" ],
"playbook_file": "ansible/site.yml"
},
{
Expand Down
131 changes: 131 additions & 0 deletions my_windows-10-enterprise-eval.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
{
"_comment": "Build with `NAME=my_windows-10-enterprise-x64-eval WINDOWS_VERSION=10 VIRTIO_WIN_ISO=/var/tmp/packer/virtio-win.iso packerio build -only=qemu my_windows-10-enterprise-eval.json`",
"variables": {
"name": "{{ env `NAME` }}",
"cpus": "2",
"memory": "4096",
"virtio_win_iso": "{{ env `VIRTIO_WIN_ISO` }}",
"iso_url": "http://care.dlservice.microsoft.com/dl/download/6/5/D/65D18931-F626-4A35-AD5B-F5DA41FE6B76/16299.15.170928-1534.rs3_release_CLIENTENTERPRISEEVAL_OEMRET_x64FRE_en-us.iso",
"iso_checksum": "3d39dd9bd37db5b3c80801ae44003802a9c770a7400a1b33027ca474a1a7c691",
"autounattend": "http/windows-{{ env `WINDOWS_VERSION` }}/Autounattend.xml",
"winrm_username": "vagrant",
"winrm_password": "vagrant",
"disk_size": "51200",
"headless": "false"
},

"builders":
[
{
"vm_name": "{{ user `name` }}",
"type": "qemu",
"iso_checksum_type": "sha256",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_urls": [ "{{ user `iso_url` }}" ],
"communicator": "winrm",
"winrm_username": "{{ user `winrm_username` }}",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "12h",
"winrm_use_ssl": "true",
"winrm_insecure": "true",
"headless": "{{ user `headless` }}",
"output_directory": "{{ user `name` }}-qemu",

"shutdown_command": "timeout 100 & C:\\Windows\\System32\\Sysprep\\sysprep.exe /generalize /oobe /shutdown /unattend:A:\\unattend.xml",
"shutdown_timeout": "15m",

"qemuargs": [[ "-m", "{{ user `memory` }}" ], [ "-smp", "{{ user `cpus` }}" ], ["-drive", "file={{ user `virtio_win_iso` }},media=cdrom,index=3"], ["-drive", "file={{ user `name` }}-qemu/{{ .Name }},if=virtio,cache=writeback,discard=ignore,format=qcow2,index=1"]],
"disk_size": "{{ user `disk_size` }}",

"floppy_files": [
"{{ user `autounattend` }}",
"scripts/win-common/fixnetwork.ps1",
"scripts/win-common/unattend.xml"
]
},
{
"vm_name": "{{ user `name` }}",
"type": "virtualbox-iso",
"guest_os_type": "Windows10_64",
"iso_checksum_type": "sha256",
"iso_checksum": "{{ user `iso_checksum` }}",
"iso_urls": [ "{{ user `iso_url` }}" ],
"communicator": "winrm",
"winrm_username": "{{ user `winrm_username` }}",
"winrm_password": "{{ user `winrm_password` }}",
"winrm_timeout": "12h",
"winrm_use_ssl": "true",
"winrm_insecure": "true",
"headless": "{{ user `headless` }}",
"output_directory": "{{ user `name` }}-virtualbox-iso",
"guest_additions_mode": "attach",

"shutdown_command": "timeout 100 & C:\\Windows\\System32\\Sysprep\\sysprep.exe /generalize /oobe /shutdown /unattend:A:\\unattend.xml",
"shutdown_timeout": "15m",

"hard_drive_interface": "sata",
"disk_size": "{{ user `disk_size` }}",
"vboxmanage": [
[
"modifyvm",
"{{ .Name }}",
"--cpus",
"{{ user `cpus` }}"
],
[
"modifyvm",
"{{ .Name }}",
"--memory",
"{{ user `memory` }}"
],
[
"modifyvm",
"{{ .Name }}",
"--audiocontroller",
"hda"
]
],

"floppy_files": [
"{{ user `autounattend` }}",
"scripts/win-common/fixnetwork.ps1",
"scripts/win-common/unattend.xml"
]
}
],
"provisioners": [
{
"type": "powershell",
"only": ["virtualbox-iso"],
"inline":
[
"$cert = (Get-AuthenticodeSignature 'E:\\VBoxWindowsAdditions.exe').SignerCertificate; [System.IO.File]::WriteAllBytes('C:\\vbox.cer', $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert));",
"certutil.exe -f -addstore TrustedPublisher C:\\vbox.cer",
"E:\\VBoxWindowsAdditions.exe /S"
]
},
{
"type": "ansible",
"user": "vagrant",
"playbook_file": "ansible/site.yml",
"extra_arguments": [
"--connection", "packer",
"--extra-vars", "ansible_shell_type=powershell ansible_shell_executable=None packer_build_name={{ user `name` }}"
]
},
{
"type": "windows-restart",
"restart_timeout": "1h"
}
],
"post-processors": [
[
{
"type": "vagrant",
"compression_level": 9,
"vagrantfile_template": "Vagrantfile-windows.template",
"output": "{{ user `name` }}-{{ .Provider }}.box"
}
]
]
}
Loading

0 comments on commit 73226ac

Please sign in to comment.