diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest_screenshot.py b/lib/ansible/modules/cloud/vmware/vmware_guest_screenshot.py index ab9d3c37b88..5ae273ea8e6 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest_screenshot.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest_screenshot.py @@ -84,7 +84,7 @@ options: downloaded from ESXi host to the local directory.' - 'If not download screenshot file to local machine, you can open it through the returned file URL in screenshot facts manually.' - type: str + type: path extends_documentation_fragment: vmware.documentation ''' @@ -142,7 +142,7 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlencode, quote from ansible.module_utils._text import to_native from ansible.module_utils.urls import open_url -from ansible.module_utils.vmware import PyVmomi, vmware_argument_spec, wait_for_task +from ansible.module_utils.vmware import PyVmomi, vmware_argument_spec, wait_for_task, get_parent_datacenter import os @@ -163,11 +163,7 @@ class PyVmomiHelper(PyVmomi): if not self.is_vcenter(): datacenter = 'ha-datacenter' else: - if self.params.get('datacenter'): - datacenter = self.params['datacenter'] - else: - datacenter = self.get_parent_datacenter(self.current_vm_obj).name - datacenter = datacenter.replace('&', '%26') + datacenter = get_parent_datacenter(self.current_vm_obj).name.replace('&', '%26') params['dcPath'] = datacenter url_path = "https://%s%s?%s" % (self.params['hostname'], path, urlencode(params)) @@ -177,8 +173,6 @@ class PyVmomiHelper(PyVmomi): response = None download_size = 0 # file is downloaded as local_file_name when specified, or use original file name - if not local_file_path.startswith("/"): - local_file_path = "/" + local_file_path if local_file_path.endswith('.png'): local_file_name = local_file_path.split('/')[-1] local_file_path = local_file_path.rsplit('/', 1)[0] @@ -268,7 +262,7 @@ def main(): datacenter=dict(type='str'), esxi_hostname=dict(type='str'), cluster=dict(type='str'), - local_path=dict(type='str'), + local_path=dict(type='path'), ) module = AnsibleModule( argument_spec=argument_spec, diff --git a/test/integration/targets/vmware_guest_screenshot/tasks/main.yml b/test/integration/targets/vmware_guest_screenshot/tasks/main.yml index 7a29538f29c..30ccf6bfdeb 100644 --- a/test/integration/targets/vmware_guest_screenshot/tasks/main.yml +++ b/test/integration/targets/vmware_guest_screenshot/tasks/main.yml @@ -11,13 +11,15 @@ setup_datastore: true setup_virtualmachines: true - - name: set state to poweroff on all VMs + - name: set VM state to powered on vmware_guest: validate_certs: False hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" - name: "{{ virtual_machines_in_cluster[0].name }}" + datacenter: "{{ dc1 }}" + folder: "{{ virtual_machines[0].folder }}" + name: "{{ virtual_machines[0].name }}" state: poweredon - name: take screenshot of virtual machine's console @@ -26,9 +28,7 @@ hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" - name: "{{ virtual_machines_in_cluster[0].name }}" - # Note: set the datacenter key because of https://github.com/ansible/ansible/issues/60565 - datacenter: "{{ dc1 }}" + name: "{{ virtual_machines[0].name }}" register: take_screenshot - debug: var=take_screenshot - name: assert the screenshot captured @@ -42,10 +42,10 @@ hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" - name: "{{ virtual_machines_in_cluster[0].name }}" + name: "{{ virtual_machines[0].name }}" local_path: "/tmp/screenshot_test.png" - # Note: set the datacenter key because of https://github.com/ansible/ansible/issues/60565 datacenter: "{{ dc1 }}" + folder: "{{ virtual_machines[0].folder }}" register: take_screenshot - debug: var=take_screenshot - name: assert the screenshot captured