Ansible: Managing Windows machines with Ansible

  • 2

This post discusses about to managing Windows machines/servers with Ansible control machine. Through WinRM, Ansible can connect to Windows machines and run PowerShell scripts. The idea of using Powershell as the main code to execute tasks in Windows systems, together with the agentless approach.

Step 1 – Prerequisites:

Ansible Control Machine :- On Ansible control machine we need to have python winrm module to be installed.

root@devopstechie$ pip install "pywinrm>=0.2.2"

Windows Machine :- In order for Ansible to manage your windows machines, you will have to enable and configure PowerShell remoting. To automate the setup of WinRM, Ansible Team(RedHat) provides examples/scripts/ConfigureRemotingForAnsible.ps1 script. We need to run above script on the remote machine in a PowerShell console as an administrator.

powershell.exe -File ConfigureRemotingForAnsible.ps1

The example script accepts a few arguments which Admins may choose to use to modify the default setup, you can find more details on Ansible official site.

Step 2 – Configure / Setup:

Once completed the prerequisites setup, you have to do following things to test Ansible Windows machine connection. create /etc/ansible/hosts inventory file, you can add the Windows machines into this file you want to manage.



Now by using Ansible win_ping module you can test connection/setup is working

[root@ansible ansible]# ansible windows -m win_ping
dc01.devopstechie.local | success >> {
    "changed": false,
    "ping": "pong"


Avinash Pawar

An automation enthusiast who presently working as DevOps Engineer.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Avinash Pawar

An automation enthusiast who presently working as DevOps Engineer.