--- - hosts: all gather_facts: no vars_files: - /etc/ansible/testing/main_vars.yml tasks: - name: VMs list task delegate_to: localhost vmware_vm_info: hostname: '{{vcenter_hostname}}' username: '{{vcenter_user}}' password: '{{vcenter_password}}' validate_certs: no vm_type: vm register: vminfo - name: finding the guest name from facts set_fact: requested_guest_name: "{{item.guest_name}}" when: - item.ip_address != "" - item.ip_address == "{{ansible_host}}" with_items: "{{vminfo.virtual_machines}}" - name: Find the guest path with the help of guest find delegate_to: localhost vmware_guest_find: hostname: "{{vcenter_hostname}}" username: "{{vcenter_user}}" password: "{{vcenter_password}}" name: "{{requested_guest_name}}" validate_certs: no when: - requested_guest_name !="" register: requested_vm_path - name: Set request VM folder path to perform vm_tools actions set_fact: ansible_vmware_guest_path: "{{requested_vm_path.folders[0]}}/{{requested_guest_name}}" - include_vars: /etc/ansible/testing/custom_vars.yml - name: debug debug: var: ansible_connection - name: Shell Commands shell: > ls -ltr register: output - debug: var: output.stdout