Ansible Playbook using ansible_connection: vmware_tools

426 views
Skip to first unread message

Glen Collins

unread,
Feb 25, 2021, 8:37:40 PM2/25/21
to Ansible Project
Hello.

   I am trying to use the ansible_connection: vmware_tools in my playbook. I have been successful in connecting and running basic commands. But I am finding when using modules like yum and there is a long task to do such a patching a linux server after being 1st built the playbook comes back with an error  saying "The guest operations agent could not be contacted" and my playbook fails. I go to the server and do a yum update and it's been fully patched. It seems to me there is a timeout issues waiting for the command to complete.

For the life of me have been unable to find any timeout parameters for the vmtools using the ansible_connection and that fails. When I tried ansible_command_timeout the module also failed.

After the failure I ran the playbook again and it came back saying there was nothing to be done. So I know the command worked and patched the server but still I"m unable to find any kind of timeout parameter for this functionally.

Any ideas?

I know I can use the command with standard SSH connection but I'm trying something new that might help use with other issues. I would like to get the vmtools connection to work as it should and expected to work.

Any help would be appreciated.

Thanks.

Glen

Glen Collins

unread,
Feb 26, 2021, 9:45:05 AM2/26/21
to Ansible Project

This might help....

Here is the pertinent portions of my playbook using the command module...

-------------------------------------------------------------------------------------

  - name: Add hostvar to running playbook
    add_host:
        hostname: "{{ vmname }}"
        ansible_connection: vmware_tools
        ansible_vmware_host: <vcenter_server>
        ansible_vmware_user: "{{ vm_username }}"
        ansible_vmware_password: "{{ vm_password }}"
        ansible_vmware_validate_certs: no
        ansible_vmware_guest_path: "{{ vm_folder_location.folders[0] | string }}/{{ vmname }}"
        ansible_vmware_tools_user: "{{ generic_username }}"
        ansible_vmware_tools_password: "{{ generic_password }}"
        ansible_user: "{{ generic_username }}"
        ansible_command_timeout: 900

#  - name: Patch Server  <<<<<<< Times out
#    yum:
#        name: "*"
#        state: "latest"
#    register: yum_output
#    delegate_to: "{{ vmname }}"

  - name: Run yum update command <<<<<<<< Times out
    command: "yum update -y"
    register: yum_output
    delegate_to: "{{ vmname }}"

-------------------------------------------------------------------------------------

Here is the trace routout....

The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 147, in run
    res = self._execute()
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 673, in _execute
    self._handler.cleanup()
  File "/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 128, in cleanup
    self._remove_tmp_path(self._connection._shell.tmpdir)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 417, in _remove_tmp_path
    tmp_rm_res = self._low_level_execute_command(cmd, sudoable=False)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 1085, in _low_level_execute_command
    rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/vmware_tools.py", line 440, in exec_command
    stdout = self.create_temporary_file_in_guest(suffix=".stdout")
  File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/vmware_tools.py", line 365, in create_temporary_file_in_guest
    return self.fileManager.CreateTemporaryFileInGuest(vm=self.vm, auth=self.vm_auth, prefix=prefix, suffix=suffix)
  File "/var/lib/awx/venv/ansible/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 706, in <lambda>
    self.f(*(self.args + (obj,) + args), **kwargs)
  File "/var/lib/awx/venv/ansible/lib/python2.7/site-packages/pyVmomi/VmomiSupport.py", line 512, in _InvokeMethod
    return self._stub.InvokeMethod(self, info, args)
  File "/var/lib/awx/venv/ansible/lib/python2.7/site-packages/pyVmomi/SoapAdapter.py", line 1397, in InvokeMethod
    raise obj # pylint: disable-msg=E0702
vim.fault.GuestOperationsUnavailable: (vim.fault.GuestOperationsUnavailable) {
   dynamicType = <unset>,
   dynamicProperty = (vmodl.DynamicProperty) [],
   msg = 'The guest operations agent could not be contacted.',
   faultCause = <unset>,
   faultMessage = (vmodl.LocalizableMessage) []
}
fatal: [vllxansprd]: FAILED! => {
    "msg": "Unexpected failure during module execution.", 
    "stdout": ""
}

-------------------------------------------------------------------------------------

Long running commands fail like "yum update -y" or using the yum module with the update all. If I run an "ls" command or
something that returns quickly, the command returns without issue.

Ideas?

Thanks,

Glen

Glen Collins

unread,
Feb 26, 2021, 9:50:06 AM2/26/21
to Ansible Project
I am using ansible version:

ansible 2.9.15
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Aug 13 2020, 02:51:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Thanks.

Glen

Glen Collins

unread,
Feb 26, 2021, 10:54:35 AM2/26/21
to Ansible Project
Well I feel stupid! This is not a timeout issue but the fact the vmtools is being patched. Something that didn't cross my mind before looking at all the process during the patching process. Actually saw the command to restart the vmtools agent.

So no issue at all.

Thanks

Glen
Reply all
Reply to author
Forward
0 new messages