need to run powershell script without copying to target host

Hi All,

i have machien Ansible running in RHEL 7
Target host: Windows server 2019

i was able run powershell script by copying from RHEL to windows ,working fine

  • name: Copy a single file
    win_copy:
    src: “{{ playbook_dir }}/files/test.ps1”
    dest: C:\Temp\test.ps1

  • name: Run a script
    win_shell: C:\temp\test.ps1

The proper way is to use the script module

`

  • name: run script
    script: test.ps1

`

It will automatically try and find ‘test.ps1’ in various folder, the files folder adjacent to the playbook is one of them, copy it across, execute, then delete the file all in 1 go. If you truly don’t want to copy across the file then your only option is to read the script using the lookup plugin and use it with win_shell

`

  • name: run script in memory
    win_shell: ‘{{ lookup(“file”, “test.ps1”) }}’

`

If this is a really large script you might read some command line length limits so it’s not always possible to do this.

Thanks Jordan, very informative, I will try options which you mentioned.