Run powershell script on Windows servers which require Powershell to be run with admin privilages

Hello All,

I want to execute one powershell script on few target servers which require powershell to be run as administrator. I am getting access denied error when i try with normal playbook.

  • name: Install software on Wndows Remote server.
    hosts: all
    tasks:

  • name: copy script
    win_copy:
    src: /tmp/install.ps1
    dest: c:\temp\install.ps1

  • name: run a powershell script
    script: install.ps1 -Install -arg ‘{{ ARGLIST }}’
    register: out1

  • debug: var=out1

I am getting access denied error when i try to execute this playbook.

There’s no such thing as UAT/“run as admin” when using WinRM (which Ansible does). What does your script do, exactly?

I could be wrong but when calling script it looks locally on the Ansible box and not the windows one. Can you specify your script without using win_copy and see what happens?

hosts: all

will try and run on all hosts in your inventory. These are unlikely to be all windows hosts.

I suggest limiting just to windows host to start with. -l option.

Also how are you running the playbook? what command line is used? where is ‘ARGLIST’ defined?

Jon