Installing VMware Tools on virtual machines using Ansible

自闭症网瘾萝莉.ら 提交于 2019-12-12 04:26:07

问题


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"

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.

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}

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 changed=0 unreachable=0
failed=0

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


回答1:


From your comment:

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.

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.

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?

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 contains more detailed information, like:

"ansible_distribution": "Microsoft Windows NT 10.0.14366.0"

You need to use:

when: ansible_os_family == "Windows"


来源:https://stackoverflow.com/questions/39398399/installing-vmware-tools-on-virtual-machines-using-ansible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!