-1

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
anonimus
  • 1
  • 1
  • [Understanding privilege escalation](https://docs.ansible.com/ansible/latest/user_guide/become.html). There is a [specific section for windows](https://docs.ansible.com/ansible/latest/user_guide/become.html#become-and-windows) at the end of the document – Zeitounator Sep 13 '22 at 15:53
  • i think "become" command is only applicable with WinRM connection from ansible, is it applicable with vmware_vm_shell ? because i tried to use become in vmware_vm_shell module, but still got same error. – anonimus Sep 14 '22 at 04:22

1 Answers1

0

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

IAmAliYousefi
  • 1,132
  • 3
  • 21
  • 33
anonimus
  • 1
  • 1