Skip to content

Commit

Permalink
my_windows template added + minor fix in the scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzickap committed Mar 16, 2018
1 parent 73226ac commit 1095cb6
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 34 deletions.
24 changes: 14 additions & 10 deletions ansible/build_remote_ssh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@
changed_when: false
register: reboot_out

- name: Reboot machne to boot to latest kernel
shell: sleep 2 && shutdown -r now "Ansible triggered reboot"
async: 1
poll: 0
ignore_errors: true
when: reboot_out.stdout | search("reboot")

- name: Wait for system to boot up
local_action: wait_for host={{ ansible_host }} port={{ ansible_port | default('22') }} delay=15
become: False
- block:
- name: As user for permission to reboot machne to boot to latest kernel
pause:
prompt: 'Please confirm you want to reboot the remote machine: {{ ansible_host }}! Press return to continue. Press Ctrl+c and then "a" to abort'

- name: Reboot machne to boot to latest kernel
shell: sleep 2 && shutdown -r now "Ansible triggered reboot"
async: 1
poll: 0
ignore_errors: true

- name: Wait for system to boot up
local_action: wait_for host={{ ansible_host }} port={{ ansible_port | default('22') }} delay=30
become: False
when: reboot_out.stdout | search("reboot")

- name: Install packages
Expand Down
38 changes: 21 additions & 17 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,27 @@ cmdline() {
packer_build() {
PACKER_FILE=$1; shift

test -d $TMPDIR || mkdir -v $TMPDIR
test -d $LOG_DIR || mkdir -v $LOG_DIR
case $PACKER_VAGRANT_PROVIDER in
libvirt )
export PACKER_BUILDER_TYPE="qemu"
if echo $PACKER_FILE | grep -q -i "windows"; then
test -f $TMPDIR/virtio-win.iso || wget $VIRTIO_WIN_ISO_URL -P $TMPDIR
export VIRTIO_WIN_ISO="$TMPDIR/virtio-win.iso"
fi
;;
virtualbox )
export PACKER_BUILDER_TYPE="virtualbox-iso"
;;
esac

echo -e "\n\n*** $NAME [$PACKER_FILE] [$PACKER_BUILDER_TYPE]\n"
$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"
if [ ! -f "${NAME}-${PACKER_VAGRANT_PROVIDER}.box" ]; then
test -d $TMPDIR || mkdir -v $TMPDIR
test -d $LOG_DIR || mkdir -v $LOG_DIR
case $PACKER_VAGRANT_PROVIDER in
libvirt )
export PACKER_BUILDER_TYPE="qemu"
if echo $PACKER_FILE | grep -q -i "windows"; then
test -f $TMPDIR/virtio-win.iso || wget $VIRTIO_WIN_ISO_URL -P $TMPDIR
export VIRTIO_WIN_ISO="$TMPDIR/virtio-win.iso"
fi
;;
virtualbox )
export PACKER_BUILDER_TYPE="virtualbox-iso"
;;
esac

echo -e "\n\n*** $NAME [$PACKER_FILE] [$PACKER_BUILDER_TYPE]\n"
$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"
else
echo -e "\n*** File ${NAME}-${PACKER_VAGRANT_PROVIDER}.box already exists. Skipping....\n";
fi
}


Expand Down
10 changes: 8 additions & 2 deletions build_all.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash -eu

export VERSION="$(date +%Y%m%d).01"
LOGFILE="/tmp/build_all.log"
LOGFILE="/var/tmp/build_all.log"

(

date

for PACKER_VAGRANT_PROVIDER in libvirt; do
Expand All @@ -13,10 +14,15 @@ LOGFILE="/tmp/build_all.log"
done

for PACKER_VAGRANT_PROVIDER in libvirt virtualbox; do
for BUILD in windows_10 windows_2016 windows_2012_r2; do
for BUILD in my_windows-10 windows-10 windows-2016 windows-2012_r2; do
./build.sh $BUILD:$PACKER_VAGRANT_PROVIDER
done
done

date

./vagrant_init_destroy_boxes.sh

date

) 2>&1 | tee $LOGFILE
120 changes: 120 additions & 0 deletions templates/my_windows-10-enterprise-eval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# [My Windows $WINDOWS_VERSION ${WINDOWS_EDITION^} Evaluation](https://www.microsoft.com/en-us/evalcenter/evaluate-windows-${WINDOWS_VERSION}-${WINDOWS_EDITION})

## Modified Windows $WINDOWS_VERSION ${WINDOWS_EDITION^} ($WINDOWS_ARCH) Evaluation base box for [libvirt](https://github.com/vagrant-libvirt/vagrant-libvirt) and [virtualbox](https://www.vagrantup.com/docs/virtualbox/) Vagrant providers

---

#### Github repository for bug reports or feature requests:

[https://github.com/ruzickap/packer-templates/](https://github.com/ruzickap/packer-templates/)


## Requirements
* [QEMU-KVM](https://en.wikibooks.org/wiki/QEMU/Installing_QEMU)
* [Vagrant](https://www.vagrantup.com/downloads.html)
* [Vagrant Libvirt Plugin](https://github.com/pradels/vagrant-libvirt#installation)
* [VirtualBox](https://www.virtualbox.org/)


## Requirements for linux distributions running Vagrant
Unfortunately you can not use the Vagrant package provided by your Linux distribution (at least for CentOS / Fedora / Debian).
These distributions doesn't support naively [Ruby library for WinRM](https://github.com/WinRb/WinRM) needed by Vagrant for "talking" to Windows.
Luckily [WinRM communicator](https://github.com/mitchellh/vagrant/tree/master/plugins/communicators/winrm) including the Ruby WinRM library is part of official Vagrant package.
You will also need the latest version of [Vagrant Libvirt Plugin](https://github.com/pradels/vagrant-libvirt#installation) supporting [libvirt channels](https://libvirt.org/formatdomain.html#elementCharChannel).

Here are the steps for latest Fedora how to install Vagrant from the official web pages:
\`\`\`
dnf remove vagrant

dnf install -y https://releases.hashicorp.com/vagrant/2.0.2/vagrant_2.0.2_x86_64.rpm

# virtualbox
dnf install -y virtualbox

# libvirt only
dnf install -y libvirt-daemon-kvm qemu-kvm libvirt-devel
vagrant plugin install vagrant-libvirt
\`\`\`


## Getting started

Install and connect to the box:

\`\`\`
mkdir ${NAME}
cd ${NAME}
vagrant init ${VAGRANT_CLOUD_USER}/${NAME}
VAGRANT_DEFAULT_PROVIDER=libvirt vagrant up
# or
VAGRANT_DEFAULT_PROVIDER=virtualbox vagrant up
\`\`\`


## Login Credentials

* Username: Administrator, vagrant
* Password: vagrant


## VM Specifications

Drivers / Devices added for the VMs for specific providers.

### Libvirt
* Libvirt Provider
* VirtIO dynamic Hard Disk (up to 50 GiB)
* VirtIO Network Interface
* QXL Video Card (SPICE display)
* Channel Device (com.redhat.spice.0)

### VirtualBox
* SATA Disk


## Configuration

#### Minimal installation - see the [Autounattend file](https://github.com/ruzickap/packer-templates/blob/master/http/windows-${WINDOWS_VERSION}/Autounattend.xml)
* UTC timezone
* IEHarden disabled
* Home Page set to "about:blank"
* First Run Wizard disabled
* Firewall allows Remote Desktop connections
* AutoActivation skipped
* DoNotOpenInitialConfigurationTasksAtLogon set to true
* WinRM (ssl) enabled
* New Network Window turned off
* Administrator account enabled
* EnableLUA
* Windows image was finalized using \`sysprep\`: [unattended.xml](https://github.com/ruzickap/packer-templates/blob/master/scripts/win-common/unattend.xml)


#### Additional Drivers installed for libvirt boxes - [VirtIO](https://fedoraproject.org/wiki/Windows_Virtio_Drivers)
Installed during installation:
* NetKVM: VirtIO Network driver
* qxldod: QXL graphics driver
* viostor: VirtIO Block driver (VirtIO SCSI controller driver)

Installed components via Ansible playbook [win.yml](https://github.com/ruzickap/packer-templates/blob/master/ansible/win.yml):
* vioscsi: Support for VirtIO SCSI pass-through controller
* Balloon: VirtIO Memory Balloon driver
* viorng: VirtIO RNG Device driver
* vioser: VirtIO Serial Driver
* vioinput: VirtIO Input Driver - support for new QEMU input devices virtio-keyboard-pci, virtio-mouse-pci, virtio-tablet-pci, virtio-input-host-pci
* pvpanic: QEMU pvpanic device driver
* qemu-ga: [Qemu Guest Agent](http://wiki.libvirt.org/page/Qemu_guest_agent)

---

* added packages: see the [common_windows_packages](https://github.com/ruzickap/ansible-role-my_common_defaults/blob/master/vars/main.yml)


#### Additional Drivers installed for virtualbox boxes
* VirtualBox Guest Additions


## Thanks to...

* https://github.com/boxcutter/windows
* https://github.com/StefanScherer/packer-windows
* https://github.com/hashicorp/best-practices
11 changes: 6 additions & 5 deletions upload_box_to_vagrantup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Box names:
* ubuntu-17.10-desktop-amd64-libvirt.box
* windows-10-enterprise-x64-eval-libvirt.box
* windows-10-enterprise-x64-eval-virtualbox.box
* my_windows-10-enterprise-x64-eval-libvirt.box
* my_windows-10-enterprise-x64-eval-virtualbox.box
* windows-server-2012-r2-standard-x64-eval-libvirt.box
* windows-server-2012-r2-standard-x64-eval-virtualbox.box
* windows-server-2016-standard-x64-eval-libvirt.box
Expand All @@ -47,7 +49,7 @@ render_template() {
cmdline() {
local VAGRANT_CLOUD_USER_BOXES=$@

if [ -z $VAGRANT_CLOUD_USER_BOXES ] || [ -z $VAGRANTUP_ACCESS_TOKEN ]; then
if [ -z "$VAGRANT_CLOUD_USER_BOXES" ] || [ -z "$VAGRANTUP_ACCESS_TOKEN" ]; then
usage
exit 0;
fi
Expand Down Expand Up @@ -86,7 +88,7 @@ cmdline() {
export WINDOWS_EDITION=`echo $VAGRANT_CLOUD_BOX_NAME | awk -F '-' '{ print $3 }'`
export NAME="${MY_NAME}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"
export SHORT_DESCRIPTION="Windows $WINDOWS_VERSION ${WINDOWS_EDITION^} ($WINDOWS_ARCH) Evaluation for libvirt and virtualbox"
export LONG_DESCRIPTION=$(render_template templates/windows-${WINDOWS_VERSION}-${WINDOWS_EDITION}-eval.md)
export LONG_DESCRIPTION=$(render_template templates/${MY_NAME}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-eval.md)
;;
*windows-*-2012-*)
export WINDOWS_VERSION=`echo $VAGRANT_CLOUD_BOX_NAME | awk -F '-' '{ print $3 }'`
Expand All @@ -96,7 +98,7 @@ cmdline() {
export WINDOWS_EDITION=`echo $VAGRANT_CLOUD_BOX_NAME | awk -F '-' '{ print $5 }'`
export NAME="${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-${WINDOWS_RELEASE}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"
export SHORT_DESCRIPTION="Windows ${WINDOWS_TYPE^} $WINDOWS_VERSION ${WINDOWS_RELEASE^^} ${WINDOWS_EDITION^} ($WINDOWS_ARCH) Evaluation for libvirt and virtualbox"
export LONG_DESCRIPTION=$(render_template templates/windows-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.md)
export LONG_DESCRIPTION=$(render_template templates/${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.md)
;;
*windows-*-2016-*)
export WINDOWS_VERSION=`echo $VAGRANT_CLOUD_BOX_NAME | awk -F '-' '{ print $3 }'`
Expand All @@ -105,7 +107,7 @@ cmdline() {
export WINDOWS_EDITION=`echo $VAGRANT_CLOUD_BOX_NAME | awk -F '-' '{ print $4 }'`
export NAME="${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-${WINDOWS_EDITION}-${WINDOWS_ARCH}-eval"
export SHORT_DESCRIPTION="Windows ${WINDOWS_TYPE^} $WINDOWS_VERSION ${WINDOWS_EDITION^} ($WINDOWS_ARCH) Evaluation for libvirt and virtualbox"
export LONG_DESCRIPTION=$(render_template templates/windows-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.md)
export LONG_DESCRIPTION=$(render_template templates/${MY_NAME}-${WINDOWS_TYPE}-${WINDOWS_VERSION}-eval.md)
;;
esac

Expand Down Expand Up @@ -158,7 +160,6 @@ vagrantup_upload() {
local PACKER_FILE=$1; shift

echo -e "\n\n*** $SHORT_DESCRIPTION ($NAME) [$PACKER_FILE]\n"
echo "$LONG_DESCRIPTION" > /tmp/${NAME}.md
create_vagrantup_box
upload_boxfile_to_vagrantup
}
Expand Down

0 comments on commit 1095cb6

Please sign in to comment.