Vagrant with Ansible for Windows VM
Asked Answered
A

2

6

I am trying to run Vagrant with Ansible on my Mac to create and provision a Windows 7 VM. I am able to "vagrant up" when I don't invoke Ansible in the Vagrantfile.

I am using the following playbook.yml

---
- hosts: all
  tasks:
    - name: run win ping
      win_ping:

When I add the ansible code to my Vagrantfile, I get the following error

GATHERING FACTS *************************************************************** 
failed: [default] => {"failed": true, "parsed": false}
/bin/sh: /usr/bin/python: No such file or directory

To me, this error means it fails to find Python because it is looking for Python as if it is a Linux machine.

Separately, I have run

ansible windows -m win_ping

where windows is the IP address to the VM brought up by Vagrant so I suspect the issue is not with Ansible but with how Vagrant is invoking Ansible.

Has anyone tried Vagrant + Ansible for a Windows VM? Is there something obvious that I am missing (perhaps an option to pass to Ansible)?

I am using Vagrant version 1.7.2 and Ansible version 1.8.3

Athodyd answered 20/2, 2015 at 19:55 Comment(2)
Can you run a which ansible and which python to check where they are located (especially the latter one). Also, can you run ansible-playbook windows -m win_ping and see if that works outside of the vagrant context? Looks like vagrant would be calling ansible-playbook internally: github.com/mitchellh/vagrant/blob/master/plugins/provisioners/…Autogenous
Also, does vagrant up --debug give you more insight?Autogenous
G
2

With Ansible provisioning a Windows box (either Vagrant, VM or real machine) the configuration is much more important in the first place. Before crafting your playbook, you should have a correct configuration in place.

Having a Windows box managed by Vagrant, your configuration file group_vars/windows-dev should contain something like:

ansible_user: IEUser
ansible_password: Passw0rd!
ansible_port: 55986 # not 5986, as we would use for non-virtualized environments
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

Be sure to insert the correct credentials and choose the right port for ansible-port. Working with Vagrant, you can get the correct port from the log-messages produced by Vagrant after a vagrant up. In my case this looks like this:

==> default: Forwarding ports...
    default: 5985 (guest) => 55985 (host) (adapter 1)
    default: 5986 (guest) => 55986 (host) (adapter 1)

My Vagrantfile could be found here, if you´re interested. It uses the Microsoft Edge on Windows 10 Stable (14.xxx) image from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms.

Now the win_ping module should work - assuming that you´ve done all the necessary preparing steps on your Windows box which center around executing the script ConfigureRemotingForAnsible.ps1 (more Information could be found in the Making Windows Ansible ready chapter in this blog post):

ansible windows-dev -i hostsfile -m win_ping

Only, if this gives you an SUCCESS you should proceed with crafting your playbook.

Genro answered 4/1, 2017 at 5:3 Comment(0)
I
0

In my Windows provisioning playbook I set this in the header:

gather_facts: no

Indiscrete answered 15/1, 2016 at 9:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.