使用Ansible for Windows VM的Vagrant

时间:2015-02-20 19:55:22

标签: vagrant ansible vagrant-windows

我正在尝试在Mac上使用Ansible运行Vagrant来创建和配置Windows 7 VM。当我不在Vagrantfile中调用Ansible时,我能够“流浪”。

我正在使用以下playbook.yml

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

当我将ansible代码添加到我的Vagrantfile时,我收到以下错误

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

对我来说,这个错误意味着它无法找到Python,因为它正在寻找Python,就好像它是一台Linux机器。

另外,我已经跑了

ansible windows -m win_ping

其中windows是Vagrant提出的VM的IP地址,所以我怀疑问题不在于Ansible,而在于Vagrant如何调用Ansible。

有人试过Vagrant + Ansible用于Windows VM吗?是否有一些我不知道的东西(也许是传递给Ansible的选项)?

我正在使用Vagrant版本1.7.2和Ansible版本1.8.3

2 个答案:

答案 0 :(得分:2)

使用Ansible配置Windows框(Vagrant,VM或真机),配置首先更为重要。在制作你的剧本之前,你应该有一个正确的配置。

拥有由Vagrant管理的Windows框,您的配置文件group_vars/windows-dev应包含以下内容:

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

请务必插入正确的凭据,并为ansible-port选择正确的端口。使用Vagrant,您可以在vagrant up之后从Vagrant生成的日志消息中获取正确的端口。就我而言,这看起来像这样:

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

我的Vagrantfile could be found here,如果您有兴趣的话。它使用来自https://developer.microsoft.com/en-us/microsoft-edge/tools/vms Microsoft Edge on Windows 10 Stable(14.xxx)图像。

现在win_ping模块应该可以运行 - 假设您已经在Windows框中执行了所有必要的准备步骤,这些步骤以执行脚本ConfigureRemotingForAnsible.ps1为中心(更多信息可以在this blog post)中创建Windows Ansible 一章:

ansible windows-dev -i hostsfile -m win_ping

只有,如果这给你SUCCESS,你应该继续制作你的剧本。

答案 1 :(得分:0)

在我的Windows配置手册中,我在标题中设置了这个:

gather_facts:没有