connection of Ubuntu to physical windows using ansible
I am Shradha Arsewar working as Associate software Engineer used to work as a Intern in Product Company (PTC). Likes to share knowledge
πΉ Steps to Connect Local Ubuntu (Master) β Physical Windows (Slave)
- Get the Windows machine ready
Enable WinRM service On the Windows machine (run PowerShell as Administrator):
winrm quickconfig
Accept prompts if asked.
Allow unencrypted/basic auth (for initial test)
winrm set winrm/config/service '@{AllowUnencrypted="true"}' winrm set winrm/config/service/auth '@{Basic="true"}'
Create a dedicated user (like ansible)
net user ansible "Ans!ble@2024#Local" /add net localgroup Administrators ansible /add
β This ensures Ubuntu can authenticate.
Configure firewall on Windows Allow inbound traffic on WinRM ports:
New-NetFirewallRule -DisplayName "Allow WinRM HTTP" -Direction Inbound -Protocol TCP -LocalPort 5985 -Action Allow New-NetFirewallRule -DisplayName "Allow WinRM HTTPS" -Direction Inbound -Protocol TCP -LocalPort 5986 -Action Allow
- Get the IP address of the Windows machine
On Windows, run:
ipconfig
Note the IPv4 address (e.g., 192.168.1.50 if in the same LAN).
β οΈ Important: Ensure Ubuntu and Windows are in the same network (same Wi-Fi or LAN) OR you have proper routing if remote.
- Prepare Ubuntu (Ansible Master)
Make sure Ansible and pywinrm are installed (you already have this).
Edit your Ansible hosts file (/etc/ansible/hosts):
[windows] 192.168.1.50 # Replace with your Windows machine IP
[windows:vars] ansible_user=ansible ansible_password=Ans!ble@2024#Local ansible_connection=winrm ansible_winrm_transport=basic ansible_port=5985
- Test connection
From Ubuntu:
ansible windows -m win_ping
Expected:
"ping": "pong"
πΉ Things to Watch Out For
Both machines must see each other on the network (ping Windows IP from Ubuntu).
If they are in different networks, you may need:
Port forwarding on the router
VPN setup (if remote access is needed)
For production: use HTTPS (5986) with SSL certificates instead of HTTP.
solution 2 to follow :
β Checklist: Connect Ubuntu (Ansible Master) β Physical Windows (Slave)
- On the Windows Physical Machine
π Open PowerShell as Administrator and run the following:
1. Enable WinRM service
winrm quickconfig
2. Allow unencrypted + basic auth (for testing)
winrm set winrm/config/service '@{AllowUnencrypted="true"}' winrm set winrm/config/service/auth '@{Basic="true"}'
3. Create Ansible user
net user ansible "Ans!ble@2024#Local" /add net localgroup Administrators ansible /add
4. Open firewall ports for WinRM
New-NetFirewallRule -DisplayName "Allow WinRM HTTP" -Direction Inbound -Protocol TCP -LocalPort 5985 -Action Allow New-NetFirewallRule -DisplayName "Allow WinRM HTTPS" -Direction Inbound -Protocol TCP -LocalPort 5986 -Action Allow
β Done β Now Windows is ready.
- On the Ubuntu Master (Ansible Controller)
π Run these on your Ubuntu terminal:
1. Make sure Ansible + pywinrm are installed
sudo apt update sudo apt install -y ansible python3-pip pip3 install pywinrm
2. Edit Ansible hosts file
sudo nano /etc/ansible/hosts
π Add this block (replace with your Windows IP):
[windows] 192.168.1.50 # π Replace with the IP from ipconfig on Windows
[windows:vars] ansible_user=ansible ansible_password=Ans!ble@2024#Local ansible_connection=winrm ansible_winrm_transport=basic ansible_port=5985
Save and exit (CTRL+O, Enter, CTRL+X).
- Test Connection
On Ubuntu:
ansible windows -m win_ping
π Expected output:
192.168.1.50 | SUCCESS => { "changed": false, "ping": "pong" }
β If you see "pong", youβre fully connected!
- Run Playbooks
Example 1 β Add a user:
save as adduser.yml
name: Add user on Windows hosts: windows tasks:
- name: Create user win_user: name: testuser password: "Password@123" state: present
Run it:
ansible-playbook adduser.yml
Example 2 β Install Chrome:
save as install_chrome.yml
name: Install Google Chrome on Windows hosts: windows tasks:
name: Download Chrome installer win_get_url: url: https://dl.google.com/chrome/install/latest/chrome_installer.exe dest: C:\chrome_installer.exe
name: Install Chrome win_package: path: C:\chrome_installer.exe state: present
Run it:
ansible-playbook install_chrome.yml
- Verify on Windows
π In PowerShell on Windows:
Check users:
Get-LocalUser
Check Chrome:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --version
π― Thatβs it! You now have a physical Windows machine managed by Ansible from Ubuntu, just like with EC2.
