community / community.vmware / 4.2.0 / module / vmware_vm_shell Run commands in a VMware guest operating system Authors: Ritesh Khadgaray (@ritzk), Abhijeet Kasurde (@Akasurde)community.vmware.vmware_vm_shell (4.2.0) — module
Install with ansible-galaxy collection install community.vmware:==4.2.0
collections: - name: community.vmware version: 4.2.0
Module allows user to run common system administration commands in the guest operating system.
- name: Run command inside a virtual machine community.vmware.vmware_vm_shell: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter }}" folder: "/{{datacenter}}/vm" vm_id: "{{ vm_name }}" vm_username: root vm_password: superSecret vm_shell: /bin/echo vm_shell_args: " $var >> myFile " vm_shell_env: - "PATH=/bin" - "VAR=test" vm_shell_cwd: "/tmp" delegate_to: localhost register: shell_command_output
- name: Run command inside a virtual machine with wait and timeout community.vmware.vmware_vm_shell: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter }}" folder: "/{{datacenter}}/vm" vm_id: NameOfVM vm_username: root vm_password: superSecret vm_shell: /bin/sleep vm_shell_args: 100 wait_for_process: true timeout: 2000 delegate_to: localhost register: shell_command_with_wait_timeout
- name: Change user password in the guest machine community.vmware.vmware_vm_shell: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter }}" folder: "/{{datacenter}}/vm" vm_id: "{{ vm_name }}" vm_username: sample vm_password: old_password vm_shell: "/bin/echo" vm_shell_args: "-e 'old_password\nnew_password\nnew_password' | passwd sample > /tmp/$$.txt 2>&1" delegate_to: localhost
- name: Change hostname of guest machine community.vmware.vmware_vm_shell: hostname: "{{ vcenter_hostname }}" username: "{{ vcenter_username }}" password: "{{ vcenter_password }}" datacenter: "{{ datacenter }}" folder: "/{{datacenter}}/vm" vm_id: "{{ vm_name }}" vm_username: testUser vm_password: SuperSecretPassword vm_shell: "/usr/bin/hostnamectl" vm_shell_args: "set-hostname new_hostname > /tmp/$$.txt 2>&1" delegate_to: localhost
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 vm_id: description: - Name of the virtual machine to work with. required: true type: str folder: description: - Destination folder, absolute or relative path to find an existing guest or create the new guest. - The folder should include the datacenter. ESX's datacenter is ha-datacenter. - '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' 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: 3600 description: - Timeout in seconds. - If set to positive integers, then O(wait_for_process=true) will honor this parameter and will exit after this timeout. type: int 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 vm_shell: description: - The absolute path to the program to start. - On Linux, shell is executed via bash. required: true type: str 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 vm_shell_cwd: description: - The current working directory of the application from which it will be run. type: str vm_shell_env: description: - Comma separated list of environment variable, specified in the guest OS notation. elements: str type: list vm_shell_args: default: ' ' description: - The argument to the program. - The characters which must be escaped to the shell also be escaped on the command line provided. 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 wait_for_process: default: false description: - If set to V(true), module will wait for process to complete in the given virtual machine. type: bool
results: description: metadata about the new process after completion with wait_for_process returned: on success sample: cmd_line: '"/bin/sleep" 1' end_time: '2018-04-26T05:03:21+00:00' exit_code: 0 name: sleep owner: dev1 start_time: '2018-04-26T05:03:19+00:00' uuid: 564db1e2-a3ff-3b0e-8b77-49c25570bb66 type: dict