Ansible - Run a command on Windows hosts using the win_command module
by
Jeremy Canfield |
Updated: May 09 2023
| Ansible articles
If you are not familiar with modules, check out Ansible - Getting Started with Modules.
The shell, command, script or raw modules are used to invoke a command on Linux nodes whereas win_command is used to run a common on Windows nodes.
In this example, the ps command will be invoked on the managed nodes. Often, this is used to run a Batch or PowerShell script on Windows nodes.
---
- hosts: all
tasks:
- name: run PowerShell example.ps1 script using win_command
command: 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe F:\Scripts\PowerShell\example.ps1'
register: out
- debug:
var: out
...
Did you find this article helpful?
If so, consider buying me a coffee over at