# connection of Ubuntu to physical windows using ansible

🔹 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

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

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

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

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

3. Test Connection
    

On Ubuntu:

ansible windows -m win\_ping

👉 Expected output:

192.168.1.50 | SUCCESS =&gt; { "changed": false, "ping": "pong" }

✅ If you see "pong", you’re fully connected!

4. 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](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

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