ansible-collections / ansible.windows

Windows core collection for Ansible
https://galaxy.ansible.com/ansible/windows
GNU General Public License v3.0
249 stars 169 forks source link

Failure in task bootstrap script (Task failed to connect to pipe): Illegal characters in path. #291

Closed virain closed 3 years ago

virain commented 3 years ago

Summary

PowerShell 5.1 on Windows 2012

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: at <ScriptBlock>, C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1634652108.962889-3395-192540985136676\task.ps1: line 38
xx.xx.xx.xx | FAILED! => {
    "changed": false,
    "failed_update_count": 0,
    "filtered_updates": [],
    "found_update_count": 0,
    "installed_update_count": 0,
    "msg": "Failure in task bootstrap script (Task failed to connect to pipe): Illegal characters in path.",
    "updates": []
}

image

Issue Type

Bug Report

Component Name

pip

Ansible Version

$ ansible --version

ansible [core 2.11.6] 
  config file = /home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 3.0.1
  libyaml = True

### Configuration

```console
$ ansible-config dump --only-changed
DEFAULT_GATHERING(/home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg) = smart
DEFAULT_ROLES_PATH(/home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg) = ['/home/ubuntu/ansible/playbook/ansible-sqlserver/roles']
DEFAULT_TIMEOUT(/home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg) = 60
DISPLAY_SKIPPED_HOSTS(/home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg) = False
HOST_KEY_CHECKING(/home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg) = False
~

OS / Environment

target OS versions:Windows2012R2

PS C:\Users\Administrator> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

image

Steps to Reproduce

ansible -i hosts win -m win_updates

Expected Results

It should have been successful because I had no problem executing in Windows 2012 R2 and PowerShell 4.0

Actual Results

ansible [core 2.11.6] 
  config file = /home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg
  configured module search path = ['/home/ubuntu/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/ubuntu/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
  jinja version = 3.0.1
  libyaml = True
Using /home/ubuntu/ansible/playbook/ansible-sqlserver/ansible.cfg as config file
host_list declined parsing /home/ubuntu/ansible/playbook/ansible-sqlserver/hosts as it did not pass its verify_file() method
script declined parsing /home/ubuntu/ansible/playbook/ansible-sqlserver/hosts as it did not pass its verify_file() method
auto declined parsing /home/ubuntu/ansible/playbook/ansible-sqlserver/hosts as it did not pass its verify_file() method
Parsed /home/ubuntu/ansible/playbook/ansible-sqlserver/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
META: ran handlers
redirecting (type: action) ansible.builtin.win_updates to ansible.windows.win_updates
redirecting (type: action) ansible.builtin.win_updates to ansible.windows.win_updates
redirecting (type: action) ansible.builtin.win_updates to ansible.windows.win_updates
<xxx.xxx.xxx> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO xxx.xxx.xxx
EXEC (via pipeline wrapper)
<xxx.xxx.xxx> PUT "/home/ubuntu/.ansible/tmp/ansible-local-38402orgx2w8/tmpun7urlxk/poll.ps1" TO "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1634652872.7356696-3844-56496826252887\poll.ps1"
<xxx.xxx.xxx> PUT "/home/ubuntu/.ansible/tmp/ansible-local-38402orgx2w8/tmph7mlifys/cancel.ps1" TO "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1634652872.7356696-3844-56496826252887\cancel.ps1"
<xxx.xxx.xxx> Running win_updates - round 1
<xxx.xxx.xxx> Starting update task
Using module file /home/ubuntu/.local/lib/python3.8/site-packages/ansible_collections/ansible/windows/plugins/modules/win_updates.ps1
Pipelining is enabled.
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
The full traceback is:
Illegal characters in path.
At C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1634652872.7356696-3844-56496826252887\task.ps1:38 char:5
+     $pipeCheck = [System.IO.Directory]::EnumerateFiles('\\.\pipe\', ' ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.IO.FileSystemEnumerableIterator`1[System.String]:FileSystemEnumerableIterator`1) [], ArgumentException
    + FullyQualifiedErrorId : BadEnumeration

ScriptStackTrace:
at <ScriptBlock>, C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1634652872.7356696-3844-56496826252887\task.ps1: line 38
xxx.xxx.xxx | FAILED! => {
    "changed": false,
    "failed_update_count": 0,
    "filtered_updates": [],
    "found_update_count": 0,
    "installed_update_count": 0,
    "invocation": {
        "module_args": {
            "accept_list": null,
            "category_names": [
                "CriticalUpdates",
                "SecurityUpdates",
                "UpdateRollups"
            ],
            "log_path": null,
            "reboot": false,
            "reboot_timeout": 1200,
            "reject_list": null,
            "server_selection": "default",
            "state": "installed",
            "use_scheduled_task": false
        }
    },
    "msg": "Failure in task bootstrap script (Task failed to connect to pipe): Illegal characters in path.",
    "updates": []
}
jborean93 commented 3 years ago

Can you run the following on your Windows host to see what happens?

[System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*')
virain commented 3 years ago

Can you run the following on your Windows host to see what happens?

[System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*')
PS C:\Users\Administrator> [System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*')
\\.\pipe\InitShutdown
\\.\pipe\lsass
\\.\pipe\ntsvcs
\\.\pipe\scerpc
\\.\pipe\Winsock2\CatalogChangeListener-230-0
\\.\pipe\epmapper
\\.\pipe\Winsock2\CatalogChangeListener-170-0
\\.\pipe\LSM_API_service
\\.\pipe\Winsock2\CatalogChangeListener-1d4-0
\\.\pipe\W32TIME_ALT
\\.\pipe\eventlog
\\.\pipe\Winsock2\CatalogChangeListener-374-0
\\.\pipe\atsvc
\\.\pipe\Winsock2\CatalogChangeListener-13c-0
\\.\pipe\wkssvc
\\.\pipe\spoolss
\\.\pipe\Winsock2\CatalogChangeListener-480-0
\\.\pipe\winreg
\\.\pipe\trkwks
\\.\pipe\srvsvc
\\.\pipe\Winsock2\CatalogChangeListener-1cc-0
\\.\pipe\Winsock2\CatalogChangeListener-700-0
\\.\pipe\TermSrv_API_service
\\.\pipe\Ctx_WinStation_API_service
\\.\pipe\SessEnvPublicRpc
\\.\pipe\TSVCPIPE-365ba63a-4648-42c3-9a67-762a0a02f821
An error occurred while enumerating through a collection: Illegal characters in path..
At line:1 char:1
+ [System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.IO.FileS...[System.String]:FileSystemEnumerableIterator`1) [],
    RuntimeException
    + FullyQualifiedErrorId : BadEnumeration
jborean93 commented 3 years ago

Interesting it looks like you have a named pipe with an a character that .NET considers as illegal and thus breaks the enumeration. Can you try the following instead and see if it continues to list the pipes from the illegal one?

$WarningAction = 'Continue'

$enumerator = [System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*').GetEnumerator()
while ($true) {
    try {
        $remaining = $enumerator.MoveNext()
    }
    catch {
        Write-Warning -Message "Failed to MoveNext: $($_.Exception.Message)"
        continue
    }

    if (-not $remaining) {
        break
    }

    $enumerator.Current
}

I'm hoping it will display the warning message but also continue on from that particular pipe that's causing the problem.

virain commented 3 years ago

Interesting it looks like you have a named pipe with an a character that .NET considers as illegal and thus breaks the enumeration. Can you try the following instead and see if it continues to list the pipes from the illegal one?

$WarningAction = 'Continue'

$enumerator = [System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*').GetEnumerator()
while ($true) {
    try {
        $remaining = $enumerator.MoveNext()
    }
    catch {
        Write-Warning -Message "Failed to MoveNext: $($_.Exception.Message)"
        continue
    }

    if (-not $remaining) {
        break
    }

    $enumerator.Current
}

I'm hoping it will display the warning message but also continue on from that particular pipe that's causing the problem.

I don't understand powershell, and it's like this:

>>
\\.\pipe\InitShutdown
\\.\pipe\lsass
\\.\pipe\ntsvcs
\\.\pipe\scerpc
\\.\pipe\Winsock2\CatalogChangeListener-240-0
\\.\pipe\epmapper
\\.\pipe\Winsock2\CatalogChangeListener-174-0
\\.\pipe\LSM_API_service
\\.\pipe\eventlog
\\.\pipe\Winsock2\CatalogChangeListener-2c8-0
\\.\pipe\atsvc
\\.\pipe\Winsock2\CatalogChangeListener-2ec-0
\\.\pipe\wkssvc
\\.\pipe\spoolss
\\.\pipe\Winsock2\CatalogChangeListener-320-0
\\.\pipe\winreg
\\.\pipe\trkwks
\\.\pipe\srvsvc
\\.\pipe\Winsock2\CatalogChangeListener-1d0-0
\\.\pipe\Winsock2\CatalogChangeListener-69c-0
\\.\pipe\TermSrv_API_service
\\.\pipe\Ctx_WinStation_API_service
\\.\pipe\SessEnvPublicRpc
\\.\pipe\Winsock2\CatalogChangeListener-1d8-0
WARNING: Failed to MoveNext: Exception calling "MoveNext" with "0" argument(s): "Illegal characters in path."
\\.\pipe\TSVCPIPE-75cff16a-de6b-4d25-b63f-5b5fb92c8a4b
\\.\pipe\PSHost.132791731517587602.2148.DefaultAppDomain.powershell
jborean93 commented 3 years ago

Thanks for running, looks like it will do the trick. Essentially you have a named pipe running on your host that .NET thinks has illegal characters and raises an error. The weird code I shared will manually move through the enumeration and ignore those particular pipes allowing it to find the one required for win_updates.

jborean93 commented 3 years ago

The PR https://github.com/ansible-collections/ansible.windows/pull/292 incorporates this change and should fix your issue.

sunilcverma commented 1 year ago

I ended up in similar error

<xxx.xxx.xxx.xxx> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO xxx.xxx.xxx.xxx
EXEC (via pipeline wrapper)
<xxx.xxx.xxx.xxx> PUT "/root/.ansible/tmp/ansible-local-32qfdzd7a7/tmpf2cc_0j4/poll.ps1" TO "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1668521120.6813464-48-227397937674959\poll.ps1"
<xxx.xxx.xxx.xxx> PUT "/root/.ansible/tmp/ansible-local-32qfdzd7a7/tmpqnvbq1x9/cancel.ps1" TO "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1668521120.6813464-48-227397937674959\cancel.ps1"
<xxx.xxx.xxx.xxx> Running win_updates - round 1
<xxx.xxx.xxx.xxx> Starting update task
Using module file /root/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_updates.ps1
Pipelining is enabled.
EXEC (via pipeline wrapper)
EXEC (via pipeline wrapper)
TASK [Pre Check for Security Updates] ******************************************
task path: /builds/SRE/ansible/app11755/test/windows-updates/playbook.yml:37
The full traceback is:
Task failed to connect to pipe
At line:483 char:13
+             throw "Task failed to connect to pipe"
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Task failed to connect to pipe:String) [], RuntimeException
    + FullyQualifiedErrorId : Task failed to connect to pipe
ScriptStackTrace:
at Invoke-AsBatchLogon, <No file>: line 483
at <ScriptBlock>, <No file>: line 1600
fatal: [xxx.xxx.xxx.xxx]: FAILED! => {
    "changed": false,
    "failed_update_count": 0,
    "filtered_updates": {},
    "found_update_count": 0,
    "installed_update_count": 0,
    "invocation": {
        "module_args": {
            "accept_list": null,
            "category_names": [
                "SecurityUpdates"
            ],
            "log_path": null,
            "reboot": false,
            "reboot_timeout": 1200,
            "reject_list": null,
            "server_selection": "default",
            "skip_optional": false,
            "state": "searched",
            "use_scheduled_task": false
        }
    },
    "msg": "Failed to invoke batch script: Task failed to connect to pipe",
    "updates": {}
}

Output of command [System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*')

PS C:\Users\btsre> [System.IO.Directory]::EnumerateFiles('\\.\pipe\', '*')
\\.\pipe\InitShutdown
\\.\pipe\lsass
\\.\pipe\ntsvcs
\\.\pipe\scerpc
\\.\pipe\Winsock2\CatalogChangeListener-70-0
\\.\pipe\epmapper
\\.\pipe\Winsock2\CatalogChangeListener-2f0-0
\\.\pipe\LSM_API_service
\\.\pipe\eventlog
\\.\pipe\Winsock2\CatalogChangeListener-458-0
\\.\pipe\atsvc
\\.\pipe\Winsock2\CatalogChangeListener-224-0
\\.\pipe\TermSrv_API_service
\\.\pipe\Ctx_WinStation_API_service
\\.\pipe\wkssvc
\\.\pipe\SessEnvPublicRpc
\\.\pipe\Winsock2\CatalogChangeListener-36c-0
\\.\pipe\trkwks
\\.\pipe\W32TIME_ALT
\\.\pipe\yvWQhjcwCqul5ChEPaGfdNYivsaiJzpIelDcwC5k2olNv6f8YmS9NXGb0HCBLaeILnMNUUrctQG9yyiDGCBpFEeUL1O0WlrW38woHs5lHJGbxTrJfJKzJJ
\\.\pipe\srvsvc
\\.\pipe\Winsock2\CatalogChangeListener-a58-0
\\.\pipe\CrowdStrike\{1A9F1ABA-7AAE-4276-88AA-40AAAD0F53BF}
\\.\pipe\Winsock2\CatalogChangeListener-944-0
\\.\pipe\vgauth-service
\\.\pipe\cygwin-7d2b541f81e048bd-4144-sigwait
\\.\pipe\cygwin-7d2b541f81e048bd-4268-sigwait
\\.\pipe\iislogpipe8ec0ae95-b356-477a-a7c9-24a0e96ff9d8
\\.\pipe\6ea2cc9a-e59f-43ce-b43b-7b00ba0b3602
\\.\pipe\Winsock2\CatalogChangeListener-344-0
\\.\pipe\CrowdStrike\{2C9EE953-4BF4-4B98-8234-2527445B0CC2}
\\.\pipe\boost_process_auto_pipe_10252_0
\\.\pipe\boost_process_auto_pipe_10252_1
\\.\pipe\boost_process_auto_pipe_10252_2
\\.\pipe\boost_process_auto_pipe_10252_3
\\.\pipe\discovery_entry_point1
\\.\pipe\discovery_entry_point2
\\.\pipe\discovery_entry_point3
\\.\pipe\discovery_entry_point4
\\.\pipe\discovery_entry_point5
\\.\pipe\discovery_entry_point
\\.\pipe\boost_process_auto_pipe_10252_8
\\.\pipe\boost_process_auto_pipe_10252_9
\\.\pipe\wbhstipmb68f7d10-67fb-4a8d-88b6-c48f8ddf40a9
\\.\pipe\wbhstipme928ffc8-87bd-4722-a3b5-5cfe09f368c4
\\.\pipe\wbhstipm96b3e8b1-954d-4d52-bbb5-810cb6e60edb
\\.\pipe\wbhstipme1dba238-e340-4e52-b45a-0e796f8b97a3
\\.\pipe\816864ee-6111-47c3-8575-ec54c31cb3b4
\\.\pipe\01378e9e-88fb-4bce-9b7c-b979f3101c97
\\.\pipe\0e902fd0-7e34-4118-8b1b-d08650285748
\\.\pipe\c8e3b4f7-d728-4407-863b-c8527b0404b6
\\.\pipe\dff7255e-d515-4af0-afcf-7c73af3c40c8
\\.\pipe\iisipm390dfea9-1483-4463-8e38-e18e5be8d46c
\\.\pipe\iislogpipe4e84ad2c-3c86-4a97-b1ab-020ef07383de
\\.\pipe\p1QFQCa2AgTi807CvTm4GcmWxzUvEZAT1myfUAgBObK5bmuuoLFrAT7A9HyT6hJmoG0HsibVcMe2JuUkmGlqlQYHq3XxYyq4P4Dt2AWyUlUCKWCMnlx1lv
\\.\pipe\CPFATP_12724_v4.0.30319
\\.\pipe\TSVCPIPE-c85f3ec1-9f1e-4bf8-a475-c29499d34133
\\.\pipe\TSVCPIPE-86eae252-4b5b-4004-854b-0d6b5b0037bc
\\.\pipe\TSVCPIPE-dddb320f-07b6-4263-a357-4788f71ccc9e
\\.\pipe\TSVCPIPE-128566ba-4310-4227-b962-85d4b43db99c
\\.\pipe\TSVCPIPE-0b1f8db5-0962-41c1-ab97-a4d459a63af8
\\.\pipe\TSVCPIPE-fe16860e-1ecb-43a1-b027-ce27300a8861
\\.\pipe\TDLN-4348-41
\\.\pipe\TDLN-11460-41
\\.\pipe\PSHost.133130127963183968.2100.DefaultAppDomain.powershell
PS C:\Users\btsre>

Versions ansible-playbook [core 2.12.6] ansible.windows:1.12.0 Target: windows Server 2016 Datacentre image