community / community.vmware / 4.2.0 / module / vmware_guest_file_operation Files operation in a VMware guest operating system without network Authors: Stéphane Travassac (@stravassac)community.vmware.vmware_guest_file_operation (4.2.0) — module
Install with ansible-galaxy collection install community.vmware:==4.2.0
collections: - name: community.vmware version: 4.2.0
Module to copy a file to a VM, fetch a file from a VM and create or delete a directory in the guest OS.
- name: Create directory inside a vm community.vmware.vmware_guest_file_operation: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter_name }}" vm_id: "{{ guest_name }}" vm_username: "{{ guest_username }}" vm_password: "{{ guest_userpassword }}" directory: path: "/test" operation: create recurse: false delegate_to: localhost
- name: copy file to vm community.vmware.vmware_guest_file_operation: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter_name }}" vm_id: "{{ guest_name }}" vm_username: "{{ guest_username }}" vm_password: "{{ guest_userpassword }}" copy: src: "files/test.zip" dest: "/root/test.zip" overwrite: false delegate_to: localhost
- name: fetch file from vm community.vmware.vmware_guest_file_operation: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter_name }}" vm_id: "{{ guest_name }}" vm_username: "{{ guest_username }}" vm_password: "{{ guest_userpassword }}" fetch: src: "/root/test.zip" dest: "files/test.zip" delegate_to: localhost
- name: If a timeout error occurs, specify a high(er) timeout value community.vmware.vmware_guest_file_operation: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter_name }}" vm_id: "{{ guest_name }}" vm_username: "{{ guest_username }}" vm_password: "{{ guest_userpassword }}" timeout: 10000 copy: src: "files/test.zip" dest: "/root/test.zip" overwrite: false delegate_to: localhost
copy: description: - Copy file to vm without requiring network. required: false suboptions: dest: description: - File destination, path must be exist. required: true type: str overwrite: default: false description: - Overwrite or not. type: bool src: description: - File source absolute or relative. required: true type: str type: dict port: default: 443 description: - The port number of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_PORT) will be used instead. type: int fetch: description: - Get file from virtual machine without requiring network. required: false suboptions: dest: description: - File destination on localhost, path must be exist. required: true type: str src: description: - The file on the remote system to fetch. - This I(must) be a file, not a directory. required: true type: str type: dict vm_id: description: - Name of the virtual machine to work with. required: true type: str folder: description: - Destination folder, absolute path to find an existing guest or create the new guest. - The folder should include the datacenter. ESX's datacenter is ha-datacenter - Used only if O(vm_id_type=inventory_path). - 'Examples:' - ' folder: /ha-datacenter/vm' - ' folder: ha-datacenter/vm' - ' folder: /datacenter1/vm' - ' folder: datacenter1/vm' - ' folder: /datacenter1/vm/folder1' - ' folder: datacenter1/vm/folder1' - ' folder: /folder1/datacenter1/vm' - ' folder: folder1/datacenter1/vm' - ' folder: /folder1/datacenter1/vm/folder2' - ' folder: vm/folder2' - ' folder: folder2' type: str cluster: description: - The cluster hosting the virtual machine. - If set, it will help to speed up virtual machine search. type: str timeout: default: 100 description: - Timeout seconds for fetching or copying a file. type: int version_added: 3.1.0 version_added_collection: community.vmware hostname: description: - The hostname or IP address of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_HOST) will be used instead. type: str password: aliases: - pass - pwd description: - The password of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_PASSWORD) will be used instead. type: str username: aliases: - admin - user description: - The username of the vSphere vCenter or ESXi server. - If the value is not specified in the task, the value of environment variable E(VMWARE_USER) will be used instead. type: str directory: description: - Create or delete a directory. - Can be used to create temp directory inside guest using mktemp operation. - mktemp sets variable C(dir) in the result with the name of the new directory. required: false suboptions: operation: choices: - create - delete - mktemp description: - Operation to perform. required: true type: str path: description: - Directory path. - Required for O(directory.operation=create) or O(directory.operation=remove). type: str prefix: description: - Temporary directory prefix. - Required for O(directory.operation=mktemp). type: str recurse: default: false description: - Not required. type: bool suffix: description: - Temporary directory suffix. - Required for O(directory.operation=mktemp). type: str type: dict datacenter: description: - The datacenter hosting the virtual machine. - If set, it will help to speed up virtual machine search. type: str proxy_host: description: - Address of a proxy that will receive all HTTPS requests and relay them. - The format is a hostname or a IP. - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_HOST) will be used instead. required: false type: str proxy_port: description: - Port of the HTTP proxy that will receive all HTTPS requests and relay them. - If the value is not specified in the task, the value of environment variable E(VMWARE_PROXY_PORT) will be used instead. required: false type: int vm_id_type: choices: - uuid - instance_uuid - dns_name - inventory_path - vm_name default: vm_name description: - The VMware identification method by which the virtual machine will be identified. type: str vm_password: description: - The password used to login-in to the virtual machine. required: true type: str vm_username: description: - The user to login in to the virtual machine. required: true type: str validate_certs: default: true description: - Allows connection when SSL certificates are not valid. Set to V(false) when certificates are not trusted. - If the value is not specified in the task, the value of environment variable E(VMWARE_VALIDATE_CERTS) will be used instead. type: bool