ANSIBLE🔗
Preparación del cliente🔗
# ==============================================================================
# SCRIPT DE PREPARACIÓN Y VERIFICACIÓN WINRM PARA ANSIBLE
# ==============================================================================
# 1. Establecer perfil de red a Privado
Set-NetConnectionProfile -NetworkCategory Private
# 2. Habilitar Ping (ICMPv4) si está deshabilitado
Get-NetFirewallRule -Name "FPS-ICMP4-ERQ-In" | Where-Object Enabled -eq "False" | Enable-NetFirewallRule
# 3. Asegurar y forzar inicio del servicio WinRM
Set-Service WinRM -StartupType Automatic
Start-Service WinRM
Enable-PSRemoting -Force
# 4. Habilitar Windows Script Host
reg add "HKCU\Software\Microsoft\Windows Script Host\Settings" /v Enabled /t REG_DWORD /d 1 /f
# 5. Descargar y ejecutar script oficial de Ansible para WinRM
Set-ExecutionPolicy Bypass -Scope Process -Force
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor 3072
$ansibleScript = (New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/ansible/ansible-documentation/refs/heads/devel/examples/scripts/ConfigureRemotingForAnsible.ps1')
Invoke-Expression $ansibleScript
# 6. Habilitar reglas de Firewall WinRM por nombre técnico (multidioma)
Enable-NetFirewallRule -Name "WINRM-HTTP-In-TCP*", "WINRM-HTTPS-In-TCP*" -ErrorAction SilentlyContinue
# ==============================================================================
# BLOQUE DE DIAGNÓSTICO FINAL
# ==============================================================================
Write-Host "`n=== 1. ESTADO DEL SERVICIO ===" -ForegroundColor Cyan
Get-Service WinRM | Select-Object Name, Status, StartType
Write-Host "`n=== 2. LISTENERS WINRM CONFIGURADOS ===" -ForegroundColor Cyan
winrm enumerate winrm/config/listener
Write-Host "`n=== 3. PUERTOS EN ESCUCHA (5985 / 5986) ===" -ForegroundColor Cyan
Get-NetTCPConnection -LocalPort 5985, 5986 -ErrorAction SilentlyContinue | Select-Object LocalAddress, LocalPort, State
Write-Host "`n=== 4. ESTADO REGLAS DE FIREWALL ===" -ForegroundColor Cyan
Get-NetFirewallRule -Name "WINRM-HTTP-In-TCP*", "WINRM-HTTPS-In-TCP*" | Select-Object Name, DisplayName, Enabled, Profile
Pruebas🔗
El inventario:
inventory.ini
[windows]
Alumno1 ansible_host=192.168.60.91 ansible_user="DAW2" ansible_connection="winrm" ansible_winrm_server_cert_validation="ignore"
Alumno2 ansible_host=192.168.60.131 ansible_user="DAW2" ansible_connection="winrm" ansible_winrm_server_cert_validation="ignore"
Alumno3 ansible_host=192.168.60.157 ansible_user="DAW2" ansible_connection="winrm" ansible_winrm_server_cert_validation="ignore"
Ejecución de conectividad:
Ejecución de playbook:
Prueba del puerto TCP desde PowerShell (Origen)🔗
Ejecuta desde un equipo con acceso a la red para ver si el puerto responde:
TcpTestSucceeded : False$\rightarrow$ Existe un Firewall intermedio (router, antivirus local, VPN) o el servicio no está escuchando en esa IP.TcpTestSucceeded : True$\rightarrow$ El puerto está abierto; el problema es de autenticación o cifrado.