Skip to content

Instantly share code, notes, and snippets.

@hxu
Last active August 29, 2015 14:01
Show Gist options
  • Save hxu/28353ac21019d0ed48fd to your computer and use it in GitHub Desktop.
Save hxu/28353ac21019d0ed48fd to your computer and use it in GitHub Desktop.
#!/bin/bash
# For bootstrapping the Vagrant box with Ansible, then provisioning the rest of the box with Ansible
# This is because Ansible is not supported in Windows, so we can't use the Ansible provisioner directly
# with Vagrant.
# Taken from and https://github.com/geerlingguy/JJG-Ansible-Windows
# Windows shell provisioner for Ansible playbooks, based on KSid's
# windows-vagrant-ansible: https://github.com/KSid/windows-vagrant-ansible
#
# @see README.md
# @author Jeff Geerling, 2014
# @version 1.0
#
# Uncomment if behind a proxy server.
# export {http,https,ftp}_proxy='http://username:password@proxy-host:80'
ANSIBLE_PLAYBOOK=$1
ANSIBLE_HOSTS=$2
TEMP_HOSTS="/tmp/ansible_hosts"
if [ ! -f /vagrant/$ANSIBLE_PLAYBOOK ]; then
echo "Cannot find Ansible playbook."
exit 1
fi
if [ ! -f /vagrant/$ANSIBLE_HOSTS ]; then
echo "Cannot find Ansible hosts."
exit 2
fi
# Install Ansible and its dependencies if it's not installed already.
# This testing for ansible is not reliable -- sometimes in /usr/bin/ansible
if [ ! -f /usr/local/bin/ansible ]; then
sudo apt-get update
echo "Installing Ansible dependencies and Git."
sudo apt-get -y install git python python-dev
echo "Installing pip via easy_install."
wget http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py && rm -f ez_setup.py
easy_install pip
# Make sure setuptools are installed crrectly.
pip install setuptools --no-use-wheel --upgrade
echo "Installing required python modules."
pip install paramiko pyyaml jinja2 markupsafe
echo "Installing Ansible."
pip install ansible
fi
cp /vagrant/${ANSIBLE_HOSTS} ${TEMP_HOSTS} && chmod -x ${TEMP_HOSTS}
echo "Running Ansible provisioner defined in Vagrantfile."
ansible-playbook /vagrant/${ANSIBLE_PLAYBOOK} --inventory-file=${TEMP_HOSTS} --extra-vars "is_windows=true" --connection=local
rm ${TEMP_HOSTS}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment