Skip to main content

Command Palette

Search for a command to run...

connection of Ubuntu to physical windows using ansible

Published
β€’3 min readβ€’View as Markdown
S

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)

  1. 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

  1. 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.

  1. 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

  1. 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)

  1. 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.

  1. 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).

  1. 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!

  1. 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

Run it:

ansible-playbook install_chrome.yml

  1. 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.