Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant with Ansible for Windows VM

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

like image 559
wir963 Avatar asked Feb 20 '15 19:02

wir963


People also ask

How do I use vagrant with Ansible?

To create the VM and start the server provisioning all you have to do is to enter the following command once you have all the files downloaded from the GITHUB repository. vagrant up command should be used to start the VM as we are starting the VM for the first time it will automatically provision it.

What is the difference between vagrant and Ansible?

Ansible can be classified as a tool in the "Server Configuration and Automation" category, while Vagrant is grouped under "Virtual Machine Management".

What is the purpose of the command vagrant up in Ansible?

Vagrant is a tool to manage virtual machine environments, and allows you to configure and use reproducible work environments on top of various virtualization and cloud platforms. It also has integration with Ansible as a provisioner for these virtual machines, and the two tools work together well.


1 Answers

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.

like image 85
jonashackt Avatar answered Nov 03 '22 01:11

jonashackt