How to Set Up an Ubuntu Control Node to Manage a Windows Machine Using Ansible

 Ansible uses SSH to manage Linux systems, but for Windows, it requires WinRM (Windows Remote Management). Below is a step-by-step guide to configure an Ubuntu-based Ansible control node to manage a Windows 10 machine.

1. Set Up Windows for Ansible

1.1 Enable WinRM on Windows:
WinRM allows Ansible to communicate with Windows machines. Run the following PowerShell commands as an administrator on the Windows machine:
winrm quickconfig
winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/winrs @{MaxMemoryPerShellMB="1024"}

         1.2 Allow WinRM Through Windows Firewall

                        New-NetFirewallRule -Name "WinRM" -DisplayName "WinRM" -Enabled True -Direction Inbound -Protocol TCP -LocalPort 5985 -Action Allow

        1.3 Create a Windows Admin User for Ansible and add to administrator group
New-LocalUser -Name "ansibleadmin" -Password (ConvertTo-SecureString "ansibleadmin#123" -AsPlainText -Force) -FullName "Admin User" -Description "Local Admin Account"

Add-LocalGroupMember -Group "Administrators" -Member "ansibleadmin"

    2. Install and Configure Ansible on Ubuntu Control Node

        2.1. Install Ansible on Ubuntu
        sudo apt update && sudo apt install ansible -y

             2.2. Install WinRM Python Module

                    sudo apt install python3-pip

                     pip install pywinrm


    3.3. Configure Ansible Inventory File
            Create or edit your inventory file (e.g., inventory.ini):
            **********************************************
[windows]
192.168.1.100  # Replace with your Windows machine’s IP address

[windows:vars]
ansible_user=ansibleadmin  # Replace with your Windows admin user
ansible_password=ansibleadmin#123
ansible_connection=winrm
ansible_port=5985
ansible_winrm_transport=basic
ansible_winrm_server_cert_validation=ignore
            **********************************************
4. Test the Connection
       ansible -i inventory.ini windows -m win_ping