need to run powershell script without copying to target host

36 views
Skip to first unread message

Pavan Nr

unread,
Apr 17, 2020, 1:10:05 PM4/17/20
to Ansible Project
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

-----------
but without copying can we run powershell scripts directly from Ansible Engine?

Jordan Borean

unread,
Apr 17, 2020, 3:22:33 PM4/17/20
to Ansible Project
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.

Pavan Nr

unread,
Apr 17, 2020, 3:55:29 PM4/17/20
to ansible...@googlegroups.com
Thanks Jordan, very informative, I will try options which you mentioned. 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/72a3b823-dcc1-4932-94f0-9e681e4a577f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages