Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:01
Show Gist options
  • Save starise/e90d981b5f9e1e39f632 to your computer and use it in GitHub Desktop.
Save starise/e90d981b5f9e1e39f632 to your computer and use it in GitHub Desktop.
Windows provisioner for bedrock-ansible
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.require_version '>= 1.5.1'
Vagrant.configure('2') do |config| = 'roots/bedrock' :private_network, ip: ''
config.vm.hostname = ''
# adjust paths relative to Vagrantfile
config.vm.synced_folder '../', '/srv/www/',
id: 'current',
owner: 'vagrant',
group: 'www-data',
mount_options: ['dmode=776', 'fmode=775']
config.vm.provider "virtualbox" do |vb|
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/current", "1"]
# 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 = ""
sh.args = "site.yml hosts"
# Standard bedrock configuration for Ansible (Mac/Linux host).
config.vm.provision :ansible do |ansible|
ansible.playbook = './site.yml'
ansible.groups = {
'wordpress-server' => ['default']
ansible.extra_vars = {
ansible_ssh_user: 'vagrant',
user: 'vagrant'
ansible.sudo = true
if Vagrant.has_plugin?('vagrant-cachier')
config.cache.scope = :box
config.cache.synced_folder_opts = {
type: :nfs,
mount_options: ['rw', 'vers=3', 'tcp', 'nolock']
# Windows provisioner for bedrock-ansible
# based on KSid/windows-vagrant-ansible
# @author Andrea Brandi
# @version 1.0
if [ ! -f /vagrant/$ANSIBLE_PLAYBOOK ]; then
echo "Ansible playbook not found."
exit 1
if [ ! -f /vagrant/$ANSIBLE_HOSTS ]; then
echo "Ansible hosts not found."
exit 2
# Create an ssh key if not already created.
if [ ! -f ~/.ssh/id_rsa ]; then
echo -e "\n\n\n" | ssh-keygen -t rsa
# 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
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} --sudo --user=vagrant --extra-vars "default_ssh_user=vagrant is_windows=true" --connection=local
Copy link

storm2k commented Sep 20, 2014

When I run this, I get these errors:

==> default: Mounting shared folders...
default: /vagrant => C:/Users/mero/Dropbox/d6ddev/bedrock-ansible
default: /srv/www/ => C:/Users/mero/Dropbox/d6ddev/
==> default: Running provisioner: shell...
default: Running: C:/Users/mero/AppData/Local/Temp/vagrant-shell20140919-120
==> default: stdin: is not a tty
==> default: Ansible hosts not found.
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

Copy link

starise commented Sep 20, 2014

Hi, please change:

      sh.args = "site.yml hosts"


      sh.args = "site.yml hosts/development"

in the Vagrantfile, then try again.

Copy link

The README file here says that additions to the default Vagranfile will be needed and it points here to get the additions.

Where do I add the additions to the default Vagrantfile?

Copy link

Updated version for the newer Vagrantfile:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment