Ansible Winrm Setup | PowerShell Winrm Setup | Ansible – Winrm basic authentication setup


Ansible winrm setup script | pip install pywinrm | ansible winrm example | ansible winrm ps1| ansible winrm | Windows and Linux Communication.

how to connect to windows machine from Linux using ansible?

Hello Guy’s ,

Hope you are doing well !!
In this video I will show you , How we can connect Windows and Linux machine through Ansible and Winrm. Please watch complete video.

Please find below commands for Linux:
sudo dnf update
sudo dnf install python3
sudo alternatives –set python /usr/bin/python3
python –version
sudo dnf install python3-virtualenv
virtualenv env
source env/bin/activate
pip install ansible
ansible –version
ansible localhost -m ping
sudo su
sudo mkdir /etc/ansible
cd /etc/ansible
sudo touch hosts
sudo vi hosts
pip install “pywinrm=0.2.2”
ansible windowsserver -m win_ping

Ansible inventory file sample:
ansible_connection = winrm
ansible_user = ‘your_windows_machine_username’
ansible_password = “your_windows_machine_password”
ansible_winrm_server_cert_validation = ignore
ansible_winrm_transport = basic
ansible_port = 5985

For Https make sure your port will be 5986

Please find below Windows PowerShell Commands:
$url = “”
$file = “$env:tempConfigureRemotingForAnsible.ps1”
(New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file)
powershell.exe -ExecutionPolicy ByPass -File $file
Set-Item -Force WSMan:localhostClientAllowunencrypted $True
Set-Item -Force WSMan:localhostServiceAllowunencrypted $True
Set-Item -Force WSMan:localhostServiceauthBasic $True

Note: Make sure run PowerShell as Administration.

If you facing any issue let me know in comments.



    • blank
      Ravi Seethai
      May 07, 2022 02:57 am Reply

      Sudo dnf update when I pass this command. Command not found . How can I rectify

    • blank
      Karthik S
      May 07, 2022 02:57 am Reply

      Good and simple. Thanks for commands

    • blank
      gaure gundappa
      May 07, 2022 02:57 am Reply

      ya it worked for me for python 2.7 version too

    • blank
      Citric acid
      May 07, 2022 02:57 am Reply

      finally found it…it works

    • blank
      Harsh Singh
      May 07, 2022 02:57 am Reply

      when I run win_ping module it give following error
      windows | UNREACHABLE! => {
      "changed": false,
      "msg": "ssl: HTTPSConnectionPool(host='', port=5986): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<urllib3.connection.VerifiedHTTPSConnection object at 0x7fb54f4afe50>, 'Connection to timed out. (connect timeout=30)'))",
      "unreachable": true

Leave us a comment