ansibleyamlvmwarevmware-tools

Possibility to Run vmware_vm_shell using Powershell as Administrator


I feel frustated to find out if ansible module vmware_vm_shell is possible to run powershell as administrator? because few command that need to run with powershell has to be elevated to administrator role.

Why i didn't use win_shell, or win_psexec? Because i want to try run the command in Windows VM Guest, without WinRM, so i don't need to access the VM using IPaddr, otherwise we can utilize vmtools as a connection in this case.

  - name: Initiate New Disk
    vmware_vm_shell:
      hostname: "{{ lookup ('env', 'VMWARE_HOST' )}}"
      username: "{{ lookup ('env', 'VMWARE_USER' )}}"
      password: "{{ lookup ('env', 'VMWARE_PASSWORD' )}}"
      vm_id: "{{ vmname }}"
      vm_username: "administrator"
      vm_password: "password123"
      vm_shell: 'C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe'
      vm_shell_args: '-ExecutionPolicy Bypass -command "Initialize-Disk -Number {{newdisk_osnum}}"'
      vm_shell_cwd: 'C:\Users\administrator\Desktop'
      wait_for_process: yes
      validate_certs: no
    delegate_to: localhost
    register: initdisk_shell

Solution

  • Finally, after few days full of pain, I found the way out, in ansible tower has feature to Privilege Escalation option in the job template configuration. after I enabled this option, finally vmware_vm_shell is able to run powershell command as administrator. So, I don't need to run command using winRM which have to disable few option that cause few vulnerability