# Vagrant with Ansible Provisioner on Windows Long story short, ansible does not work on a Windows control machine, so you basically have to: * either run `ansible --connection=local ...` in the target vm * set up a separate control vm where ansible is installed via shell provisioner Below are `Vagrantfile` examples for both approaches ## Within the Target VM This requires the [vagrant-guest_ansible](https://github.com/vovimayhem/vagrant-guest_ansible) plugin to be installed (v0.0.2.dev, see [this pull request](https://github.com/vovimayhem/vagrant-guest_ansible/pull/6)). Vagrantfile: ```ruby Vagrant.configure("2") do |config| config.vm.box = "hansode/centos-6.5-x86_64" provisioner = Vagrant::Util::Platform.windows? ? :guest_ansible : :ansible config.vm.define "web" do |web| web.vm.network :private_network, ip: "192.168.33.13" web.vm.hostname = "web" web.vm.provision provisioner do |ansible| ansible.playbook = "provisioning/playbook.yml" end end config.vm.define "db" do |db| db.vm.network :private_network, ip: "192.168.33.14" db.vm.hostname = "db" db.vm.provision provisioner do |ansible| ansible.playbook = "provisioning/playbook.yml" end end end ``` ## From a Separate Control VM This does not require any additional plugins, but needs a [shell script to install ansible](https://gist.githubusercontent.com/tknerr/140fe6431953cc7dddfd/raw/install_ansible.sh) in the control VM: Vagrantfile: ```ruby Vagrant.configure("2") do |config| config.vm.box = "hansode/centos-6.5-x86_64" config.vm.define "web" do |web| web.vm.network :private_network, ip: "192.168.33.13" web.vm.hostname = "web" web.vm.synced_folder ".", "/vagrant", disabled: true end config.vm.define "db" do |db| db.vm.network :private_network, ip: "192.168.33.14" db.vm.hostname = "db" db.vm.synced_folder ".", "/vagrant", disabled: true end # # this is our ansible controller VM which provisions the other VMs # config.vm.define "controller" do |controller| controller.vm.network :private_network, ip: "192.168.33.15" controller.vm.hostname = "controller" # install ansible controller.vm.provision "shell", privileged: false, path: "install_ansible.sh" # run ansible controller.vm.provision "shell", privileged: false, inline: <<-EOF if [ ! -f /home/vagrant/.ssh/id_rsa ]; then wget --no-check-certificate https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant -O /home/vagrant/.ssh/id_rsa wget --no-check-certificate https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/id_rsa.pub chmod 600 /home/vagrant/.ssh/id_* fi rm -rf /tmp/provisioning cp -r /vagrant/provisioning /tmp/provisioning cd /tmp/provisioning chmod -x hosts export ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook playbook.yml --inventory-file=hosts EOF end end ```