Ansible controller node cannot connect to EC2 instance with WinRM when the instance created

  amazon-ec2, ansible, windows, winrm

Ansible controller node cannot connect to Windows EC2 instance with WinRM when the instance created.

It always failed until I remote to the target server with Remote Desktop.

I have not changed any WinRM configurations.

Ansible: 2.9
Target server: Windows Server 2016 with Base (Amazon Image)

Before remote

10.0.168.87 | UNREACHABLE! => {
    "changed": false, 
    "msg": "ntlm: HTTPConnectionPool(host='10.0.168.87', port=5985): Max retries exceeded with url: /wsman (Caused by ConnectTimeoutError(<requests.packages.urllib3.connection.HTTPConnection object at 0x7f198de0e810>, 'Connection to 10.0.168.87 timed out. (connect timeout=30)'))", 
    "unreachable": true
}

After remote

10.0.168.87 | SUCCESS => {
    "ansible_facts": {
        "ansible_architecture": "64-bit", 
        "ansible_bios_date": "08/24/2006", 
        "ansible_bios_version": "4.2.amazon", 
        "ansible_date_time": {
            "date": "2021-03-25", 
            "day": "25", 
            "epoch": "1616650572.39314", 
            "hour": "05", 
            "iso8601": "2021-03-25T05:36:12Z", 
            "iso8601_basic": "20210325T053612393142", 
            "iso8601_basic_short": "20210325T053612", 
            "iso8601_micro": "2021-03-25T05:36:12.393142Z", 
            "minute": "36", 
            "month": "03", 
            "second": "12", 
            "time": "05:36:12", 
            "tz": "UTC", 
            "tz_offset": "+00:00", 
            "weekday": "Thursday", 
            "weekday_number": "4", 
            "weeknumber": "12", 
            "year": "2021"
        }, 
        "ansible_distribution": "Microsoft Windows Server 2016 Datacenter", 
        "ansible_distribution_major_version": "10", 
        "ansible_distribution_version": "10.0.14393.0", 
        "ansible_domain": "", 
        "ansible_env": {
            "ALLUSERSPROFILE": "C:ProgramData", 
            "APPDATA": "C:UsersAdministratorAppDataRoaming", 
            "COMPUTERNAME": "EC2AMAZ-IBT4CB5", 
            "ComSpec": "C:Windowssystem32cmd.exe", 
            "CommonProgramFiles": "C:Program FilesCommon Files", 
            "CommonProgramFiles(x86)": "C:Program Files (x86)Common Files", 
            "CommonProgramW6432": "C:Program FilesCommon Files", 
            "HOMEDRIVE": "C:", 
            "HOMEPATH": "UsersAdministrator", 
            "LOCALAPPDATA": "C:UsersAdministratorAppDataLocal", 
            "LOGONSERVER": "\EC2AMAZ-IBT4CB5", 
            "NUMBER_OF_PROCESSORS": "1", 
            "OS": "Windows_NT", 
            "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.CPL", 
            "PROCESSOR_ARCHITECTURE": "AMD64", 
            "PROCESSOR_IDENTIFIER": "Intel64 Family 6 Model 63 Stepping 2, GenuineIntel", 
            "PROCESSOR_LEVEL": "6", 
            "PROCESSOR_REVISION": "3f02", 
            "PROMPT": "$P$G", 
            "PSExecutionPolicyPreference": "Unrestricted", 
            "PSModulePath": "C:UsersAdministratorDocumentsWindowsPowerShellModules;C:Program FilesWindowsPowerShellModules;C:Windowssystem32WindowsPowerShellv1.0Modules;C:Program Files (x86)AWS ToolsPowerShell", 
            "PUBLIC": "C:UsersPublic", 
            "Path": "C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;C:Program FilesAmazoncfn-bootstrap;C:UsersAdministratorAppDataLocalMicrosoftWindowsApps", 
            "ProgramData": "C:ProgramData", 
            "ProgramFiles": "C:Program Files", 
            "ProgramFiles(x86)": "C:Program Files (x86)", 
            "ProgramW6432": "C:Program Files", 
            "SystemDrive": "C:", 
            "SystemRoot": "C:Windows", 
            "TEMP": "C:UsersADMINI~1AppDataLocalTemp", 
            "TMP": "C:UsersADMINI~1AppDataLocalTemp", 
            "USERDOMAIN": "EC2AMAZ-IBT4CB5", 
            "USERDOMAIN_ROAMINGPROFILE": "EC2AMAZ-IBT4CB5", 
            "USERNAME": "Administrator", 
            "USERPROFILE": "C:UsersAdministrator", 
            "windir": "C:Windows"
        }, 
        "ansible_fqdn": "EC2AMAZ-IBT4CB5", 
        "ansible_hostname": "EC2AMAZ-IBT4CB5", 
        "ansible_interfaces": [
            {
                "connection_name": "Ethernet", 
                "default_gateway": "10.0.168.65", 
                "dns_domain": "ap-southeast-1.compute.internal", 
                "interface_index": 4, 
                "interface_name": "AWS PV Network Device #0", 
                "macaddress": "06:C0:0F:5C:CB:38"
            }
        ], 
        "ansible_ip_addresses": [
            "10.0.168.87", 
            "fe80::90e:d840:bb61:52c1"
        ], 
        "ansible_kernel": "10.0.14393.0", 
        "ansible_lastboot": "2021-03-25 04:29:19Z", 
        "ansible_machine_id": "S-1-5-21-555263589-2197952041-3497458368", 
        "ansible_memtotal_mb": 1024, 
        "ansible_netbios_name": "EC2AMAZ-IBT4CB5", 
        "ansible_nodename": "EC2AMAZ-IBT4CB5", 
        "ansible_os_family": "Windows", 
        "ansible_os_name": "Microsoft Windows Server 2016 Datacenter", 
        "ansible_os_product_type": "server", 
        "ansible_owner_contact": "", 
        "ansible_owner_name": "EC2", 
        "ansible_powershell_version": 5, 
        "ansible_processor": [
            "GenuineIntel", 
            "Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz"
        ], 
        "ansible_processor_cores": 1, 
        "ansible_processor_count": 1, 
        "ansible_processor_threads_per_core": 1, 
        "ansible_processor_vcpus": 1, 
        "ansible_product_name": "HVM domU", 
        "ansible_product_serial": "ec22c641-4df4-637e-3bf0-d01c1809fefe", 
        "ansible_reboot_pending": null, 
        "ansible_swaptotal_mb": 0, 
        "ansible_system": "Win32NT", 
        "ansible_system_description": "", 
        "ansible_system_vendor": "Xen", 
        "ansible_uptime_seconds": 4038, 
        "ansible_user_dir": "C:UsersAdministrator", 
        "ansible_user_gecos": "", 
        "ansible_user_id": "Administrator", 
        "ansible_user_sid": "S-1-5-21-555263589-2197952041-3497458368-500", 
        "ansible_virtualization_role": "guest", 
        "ansible_virtualization_type": "Xen", 
        "ansible_windows_domain": "WORKGROUP", 
        "ansible_windows_domain_member": false, 
        "ansible_windows_domain_role": "Stand-alone server", 
        "gather_subset": [
            "all"
        ], 
        "module_setup": true
    }, 
    "changed": false
}

Source: Windows Questions

LEAVE A COMMENT