Adding windows client to Ansible Inventory manually (WinRM)
Step 01: Enable WinRM
# Enable WinRM service
Enable-PSRemoting -Force
# Set WinRM service to auto-start
Set-Service WinRM -StartupType Automatic
Start-Service WinRM
# Verify
winrm quickconfig
# Allow unencrypted (HTTP) — only for testing
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
# Enable basic auth
winrm set winrm/config/service/auth '@{Basic="true"}'
# Increase memory per shell (critical for large tasks)
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}'
# Increase max envelope size
winrm set winrm/config '@{MaxEnvelopeSizekb="500"}'
# Set max concurrent operations
winrm set winrm/config/service '@{MaxConcurrentOperationsPerUser="50"}'
# Allow WinRM HTTP (5985) — only if needed
New-NetFirewallRule -Name "WinRM-HTTP" -DisplayName "WinRM HTTP" -Enabled True -Direction Inbound -Protocol TCP -LocalPort 5985 -Action Allow
Step 03: Enabling WinRM over HTTPS
# Create self-signed certificate
$cert = New-SelfSignedCertificate -DnsName "$env:COMPUTERNAME" -CertStoreLocation Cert:\LocalMachine\My
# Create HTTPS listener
winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname=`"$env:COMPUTERNAME`";CertificateThumbprint=`"$($cert.Thumbprint)`"}"
# Verify listeners
winrm enumerate winrm/config/listener
# Allow WinRM HTTPS (5986)
New-NetFirewallRule -Name "WinRM-HTTPS" -DisplayName "WinRM HTTPS" -Enabled True -Direction Inbound -Protocol TCP -LocalPort 5986 -Action Allow
Step 04: Enable Local Admin Account
# Enable LocalAccountTokenFilterPolicy
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" -Name "LocalAccountTokenFilterPolicy" -Value 1 -Type DWord
Step 05: Inventory File for HTTP
[windows]
win-01 ansible_host=192.168.1.100
[windows:vars]
ansible_user=Administrator
ansible_password=SecurePassword123!
ansible_connection=winrm
ansible_port=5985
ansible_winrm_transport=basic
ansible_winrm_scheme=http
Step 06: Inventory File for HTTPS
[windows:vars]
ansible_user=Administrator
ansible_password={{ vault_win_password }}
ansible_connection=winrm
ansible_port=5986
ansible_winrm_transport=ntlm
ansible_winrm_scheme=https
ansible_winrm_server_cert_validation=ignore