Skip to content

Instantly share code, notes, and snippets.

@irvingpop
Last active December 22, 2016 23:54
Show Gist options
  • Save irvingpop/7c46c11a7292c66db22422d59f3e5429 to your computer and use it in GitHub Desktop.
Save irvingpop/7c46c11a7292c66db22422d59f3e5429 to your computer and use it in GitHub Desktop.
Install a Windows build node
#!/bin/bash -ex
# All of this is to be run from the Automate server, assumes you have a ChefDK installed there
# Step 0, supply the right windows IP, username, password
WINDOWS_HOST='10.42.46.165'
WINDOWS_USER='Administrator'
WINDOWS_PASSWORD='VerySecurePassword'
# Step 1, configure a chef/knife client
mkdir .chef
CHEF_SERVER=`grep chef_server /etc/delivery/delivery.rb | awk '{print $3}'`
CHEF_USERNAME=`grep chef_username /etc/delivery/delivery.rb | awk '{print $3}'`
cat > .chef/knife.rb <<EOF
node_name ${CHEF_USERNAME}
chef_server_url ${CHEF_SERVER}
client_key "/etc/delivery/delivery.pem"
validation_key "/nonexist" # for validatorless bootstrapping
EOF
eval "$(chef shell-init bash)"
chef gem install knife-windows
# Step 2, install ChefDK on the windows node
# Verify that `knife wsman` can work successfully before proceeding
# If not, you need to run: https://gist.github.com/vinyar/6735863
knife wsman test $WINDOWS_HOST -m
# For now, use the community push jobs cookbook
cat > ~/Berksfile <<EOF
source 'https://supermarket.chef.io'
cookbook 'push-jobs'
EOF
# Because SSL is hard
mkdir -p ~/.berkshelf
cat > ~/.berkshelf/config.json <<EOF
{
"ssl": {
"verify": false
}
}
EOF
berks install
berks upload
# knife winrm $WINDOWS_HOST "powershell { . { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install -project chefdk }" -x $WINDOWS_USER -P $WINDOWS_PASSWORD -m --winrm-shell elevated
# Perform a validatorless bootstrap and install ChefDK all in one pass
DOWNLOAD_URL=`mixlib-install download chefdk --url --platform=windows --platform-version=2008r2 --architecture x86_64 |grep packages.chef.io`
PJ_DOWNLOAD_URL=`mixlib-install download push-jobs-client --url --platform=windows --platform-version=2008r2 --architecture x86_64 |grep packages.chef.io`
# TODO, figure out why we need to grab the push-jobs-client package when it is part of ChefDK, but the push-jobs cookbook can't grok that
cat > ~/wbn-json-attributes.json <<EOF
{
"push_jobs": {
"package_url": "${PJ_DOWNLOAD_URL}",
"package_checksum": "3b979f8d362738c8ac126ace0e80122a4cbc53425d5f8cf9653cdd79eca16d62"
}
}
EOF
knife bootstrap windows winrm \
$WINDOWS_HOST \
--node-name windows-build-node-1 \
--winrm-user $WINDOWS_USER \
--winrm-password $WINDOWS_PASSWORD \
--msi-url $DOWNLOAD_URL \
--run-list 'recipe[push-jobs::default]' \
--json-attribute-file ~/wbn-json-attributes.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment