简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM