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

    22
    5



    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
    exit
    pip install “pywinrm=0.2.2”
    ansible windowsserver -m win_ping

    Ansible inventory file sample:
    [windows]
    172.31.16.245
    [windows:vars]
    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 = “https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1”
    $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.

    Thanks.

    source

    Previous articleCreate an empty file – Ansible module file
    Next articleAnsible for the Windows Admin by Jeremy Murrah

    5 COMMENTS

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