Last active
August 29, 2015 14:01
-
-
Save starise/e90d981b5f9e1e39f632 to your computer and use it in GitHub Desktop.
Windows provisioner for bedrock-ansible
This file contains 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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
Vagrant.require_version '>= 1.5.1' | |
Vagrant.configure('2') do |config| | |
config.vm.box = 'roots/bedrock' | |
config.vm.network :private_network, ip: '192.168.50.5' | |
config.vm.hostname = 'example.dev' | |
if !Vagrant.has_plugin? 'vagrant-hostsupdater' | |
puts 'vagrant-hostsupdater missing, please install the plugin:' | |
puts 'vagrant plugin install vagrant-hostsupdater' | |
else | |
# If you have multiple sites/hosts on a single VM | |
# uncomment and add them here | |
#config.hostsupdater.aliases = %w(site2.dev) | |
end | |
# adjust paths relative to Vagrantfile | |
config.vm.synced_folder '../example.dev', '/srv/www/example.dev/current', | |
id: 'current', | |
owner: 'vagrant', | |
group: 'www-data', | |
mount_options: ['dmode=776', 'fmode=775'] | |
config.vm.provider "virtualbox" do |vb| | |
# Enable symlink creation | |
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"] | |
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/current", "1"] | |
# Fix for slow external network connections | |
vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on'] | |
vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on'] | |
end | |
# Check if we are on Windows using rbconfig | |
require 'rbconfig' | |
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/) | |
if is_windows | |
# Provisioning configuration for shell script (Windows host) | |
config.vm.provision "shell" do |sh| | |
sh.path = "windows.sh" | |
sh.args = "site.yml hosts/development" | |
end | |
else | |
# Standard bedrock configuration for Ansible (Mac/Linux host). | |
config.vm.provision :ansible do |ansible| | |
# adjust paths relative to Vagrantfile | |
ansible.playbook = './site.yml' | |
ansible.groups = { | |
'web' => ['default'], | |
'development' => ['default'] | |
} | |
ansible.extra_vars = { | |
ansible_ssh_user: 'vagrant', | |
user: 'vagrant' | |
} | |
ansible.sudo = true | |
end | |
end | |
end |
This file contains 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 | |
# | |
# Windows provisioner for bedrock-ansible | |
# based on KSid/windows-vagrant-ansible | |
# @author Andrea Brandi | |
# @version 1.0 | |
ANSIBLE_PLAYBOOK=$1 | |
ANSIBLE_HOSTS=$2 | |
TEMP_HOSTS="/tmp/ansible_hosts" | |
if [ ! -f /vagrant/$ANSIBLE_PLAYBOOK ]; then | |
echo "Ansible playbook not found." | |
exit 1 | |
fi | |
if [ ! -f /vagrant/$ANSIBLE_HOSTS ]; then | |
echo "Ansible hosts not found." | |
exit 2 | |
fi | |
# Create an ssh key if not already created. | |
if [ ! -f ~/.ssh/id_rsa ]; then | |
echo -e "\n\n\n" | ssh-keygen -t rsa | |
fi | |
# Install Ansible and its dependencies if not installed. | |
if [ ! -f /usr/bin/ansible ]; then | |
echo "Adding Ansible repository..." | |
sudo apt-add-repository ppa:rquillo/ansible | |
echo "Updating system..." | |
sudo apt-get -y update | |
echo "Installing Ansible..." | |
sudo apt-get -y 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} --connection=local | |
rm ${TEMP_HOSTS} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version for the newer Vagrantfile: https://gist.github.com/swalkinshaw/5266b6869fcbbedf074d