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

查看:67
本文介绍了使用 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] => {"changed": false, "skip_reason":条件检查失败",跳过":true}

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] => {"changed": false, "skip_reason":条件检查失败",跳过":true}

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}

播放回顾************************************************************************* myhost.com : ok=1已更改=0无法访问=0
失败=0

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

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

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

推荐答案

来自您的评论:

我的假设是,一旦您连接到主机系统,它就可以访问每个虚拟机并检查分发是否匹配,如果匹配,它会在虚拟机上安装 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 必须连接到每个虚拟机并在该机器上运行 playbook.无法将任务委派给主机.

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天全站免登陆