使用Ansible在虚拟机上安装VMware Tools [英] Installing VMware Tools on virtual machines using Ansible

查看:165
本文介绍了使用Ansible在虚拟机上安装VMware Tools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在客户机上的各种操作系统上安装VMware Tools.这是我现在的代码.

I am trying to install VMware Tools on various OS on my guest machines. This is the code I have now.

---
- hosts: all

  tasks:
        -   name: debian | installing open-vm-tools
            apt: name=open-vm-tools state=present
            when: ansible_os_family == "Debian"

        -   name: install vmware tools via Chocolatey
            win_chocolatey: name=vmware-tools state=present
            when: ansible_distribution  == "Windows"

这是我的hosts.ini文件的样子:

This is what my hosts.ini file looks like:

[my-host]
myhost.com  ansible_ssh_pass=mypw ansible_ssh_user=root

这是我用来运行它的命令.哪个可行.

This is the command I am using to run it. Which works.

ansible-playbook -i hosts.ini vmwaretools.yml

但是,这是我运行它后收到的消息.

However, this is the message I get after I run it.

好:[myhost.com]
任务[debian |安装open-vm-tools] *******************************************任务路径:/Users/Desktop/Ansible/vmwaretools .yml:5跳过: [myhost.com] => {已更改":false,"skip_reason": 条件检查失败",已跳过":是}

ok: [myhost.com]
TASK [debian | installing open-vm-tools] *************************************** task path: /Users/Desktop/Ansible/vmwaretools.yml:5 skipping: [myhost.com] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

任务[通过Chocolatey安装vmware工具] ******************************************任务路径:/Users/Desktop/Ansible/vmwaretools.yml :9正在跳过: [myhost.com] => {已更改":false,"skip_reason": 条件检查失败",已跳过":是}

TASK [install vmware tools via Chocolatey] ************************************* task path: /Users/Desktop/Ansible/vmwaretools.yml:9 skipping: [myhost.com] => {"changed": false, "skip_reason": "Conditional check failed", "skipped": true}

PLAY RECAP ****************************************************** ******************* myhost.com:ok = 1更改= 0 =无法访问= 0
失败= 0

PLAY RECAP ********************************************************************* myhost.com : ok=1 changed=0 unreachable=0
failed=0

为什么说条件检查失败?我确定我有运行Debian和Windows的VM.知道为什么会这样吗?

Why does it say conditional fail checked? I am sure I have VMs with Debian and Windows running. Any idea why this is happening?

推荐答案

来自您的评论:

我的假设是,一旦连接到主机系统,它就可以访问每个VM,并检查发行版本是否匹配,如果匹配,它将在VM上安装vmware工具.

My assumption is that, once you connect to the host system, it has access to each VM and checks to see if the distribution matches, and if it does, it installs vmware tools on the VM.

不. Ansible必须连接到每个虚拟机,并在该虚拟机上运行剧本.无法将任务委派给主机.

No. Ansible must connect to each single virtual machine and run playbook on that machine. There is no way of delegating the tasks to the host machine.

即使您运行ESXi主机并在特定计算机上选择安装VMware Tools",它唯一要做的就是将ISO映像装载到计算机上.然后,安装过程将在本地进行(通过手动管理员操作或通过自动运行).

Even when you run an ESXi host and select "Install VMware Tools" on a particular machine, the only thing it does is mounting an ISO image to the machine. The installation process then takes place locally (either by manual administrator action or through the autorun).

为什么说条件检查失败?

Why does it say conditional fail checked?

您正在不是Debian的VMware主机上运行剧本.第二个条件永远不会成立:

You are running the playbook on the VMware host machine which is not Debian. The second condition will never be true:

when: ansible_distribution == "Windows"

ansible_distribution包含更详细的信息,例如:

ansible_distribution contains more detailed information, like:

"ansible_distribution": "Microsoft Windows NT 10.0.14366.0"

您需要使用:

when: ansible_os_family == "Windows"

这篇关于使用Ansible在虚拟机上安装VMware Tools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆