Open Command prompt as RunAsAdministrator and install setup.exe

40 views
Skip to first unread message

mvram...@gmail.com

unread,
Nov 13, 2018, 5:42:30 AM11/13/18
to Ansible Project
Hi Team,

I want to open command prompt as runas administrator to install my setup.exe file in windows.
below is my playbook.

[Setup_install.yml]
---
- hosts: windows
  user: testuser

  tasks:

  - name: Install my seup.exe file.
    win_command: 'C:\temp\setup.exe /SP /VERYSILENT /DIR=C:/temp /LOG=C:/temp/Install.log'
    become: yes
    become_method: runas
    become_user: Administrator

below is my inventory file.

[windows]

[windows:vars]
ansible_ssh_user=testuser
ansible_ssh_pass=xxxxxxx
ansible_ssh_port=5986
ansible_connection=winrm
ansible_winrm_scheme=https
ansible_winrm_server_cert_validation=ignore
ansible_winrm_transport=ntlm
ansible_become_user=administrator
ansible_become_pass=xxxxxxx


When i execute setup_install.yml file, below is the output and its not completing the task.



PLAY [windows] *********************************************************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************************************************************

TASK [Install my seup.exe file.] *********************************************************************************************************************************


Can some one please help me on this.

Thanks

Brad Van Orden

unread,
Nov 13, 2018, 7:30:13 AM11/13/18
to Ansible Project
My first guess is case of administrator.  In your task, you have the first letter capitalized.  In your inventory file, it is lowercase.

Jordan Borean

unread,
Nov 13, 2018, 3:23:29 PM11/13/18
to Ansible Project
Become isn't necessarily used to 'run as administrator' in Windows but rather to change the logon from a network to interactive logon with credentials to use for delegation. Normally a WinRM process is run with the full Administrative rights of an account and you can verify that by running

- name: getlogon details for current user
  win_whoami
:

This will return a whole bunch of information but if the label key contains a 'High Mandatory Label' you know you are running as an admin. In older versions of Ansible, a become task may not have admin rights and since 2.5 it is done as a best effort attempt. I would do the below to verify you are least get the High Mandatory Label returned when using become to verify that process is run with admin rights as well.

- name: test whoami with become
  win_whoami
:

  become
: yes
  become_method
: runas
  become_user
: Administrator

As for why the process is still running it could be a few different things;
  • Become runs the task in a pseudo interactive logon so it may be prompting the user for something causing it to hang
  • The args you are using aren't the correct silent args for the process
  • Some else?
What I would try
  • Run the same command locally and see if it works or not
  • Check the log file when being installed with Ansible to see if there's anything in there that might indicate what it's waiting for
  • Try running the task with async and become, this changes a few things with how the console is spawned and killed so may work for you
  • Use procexp to see what processes are still running, whether the main powershell exe that executes the module is still running, if setup.exe is still running and so on.

Thanks

Jordan

mvram...@gmail.com

unread,
Nov 14, 2018, 2:18:46 AM11/14/18
to Ansible Project
Thanks Jordan for your prompt response.

Issue was with argument which i was passing in win_command. 
win_command: 'C:\temp\setup.exe /SP /VERYSILENT /DIR=C:/temp /LOG=C:/temp/Install.log'

Here temp directory was not there to create log file but after creating temp directory, i'm able to install setup.exe file successfully.

Also as you mentioned, become method is not require to run 'RunAs Administrator'. I'm able to install setup.exe without become method.

Regards,
Venkat
Reply all
Reply to author
Forward
0 new messages