Ansible/Windows: Difference between revisions
< Ansible
| Line 24: | Line 24: | ||
</pre> | </pre> | ||
== Test Connection == | |||
ansible -i ~/ansible/hosts windows -m win_ping | ansible -i ~/ansible/hosts windows -m win_ping | ||
# SUCCESS => { "changed": false, "ping": "pong" } | # SUCCESS => { "changed": false, "ping": "pong" } | ||
Revision as of 21:26, 29 December 2025
Ansible for Windows
Enable WinRM
Option A - Official Script
https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1
$url = "https://raw.githubusercontent.com/ansible/ansible-documentation/devel/examples/scripts/ConfigureRemotingForAnsible.ps1" $file = "$env:temp\ConfigureRemotingForAnsible.ps1" (New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file) powershell.exe -ExecutionPolicy Bypass -File $file -SkipNetworkProfileCheck -Verbose
Option B - Manual
NOTE: CHANGE TARGET_HOSTNAME
$newCert = New-SelfSignedCertificate -DnsName "[TARGET_HOSTNAME]" -CertStoreLocation Cert:\LocalMachine\My
$thumb = $newCert.Thumbprint
winrm create winrm/config/Listener?Address=*+Transport=HTTPS "@{Hostname="[TARGET_HOSTNAME]"; CertificateThumbprint="$thumb"}"
netsh advfirewall firewall add rule name="WinRM-HTTPS" dir=in action=allow protocol=TCP localport=5986
Test-WSMan -ComputerName [TARGET_HOSTNAME] -UseSSL
Test Connection
ansible -i ~/ansible/hosts windows -m win_ping
# SUCCESS => { "changed": false, "ping": "pong" }