ansible-collections / ansible.windows

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

win_updates.ps1 | Failed to invoke batch script: Task failed to connect to pipe #448

Closed sunilcverma closed 1 year ago

sunilcverma commented 1 year ago
SUMMARY
ISSUE TYPE
COMPONENT NAME

ansible.windows.win_updates

ANSIBLE VERSION
ansible-playbook [core 2.12.6]

ansible.windows:1.12.0
COLLECTION VERSION
# /usr/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    2.2.0  
ansible.netcommon             2.6.1  
ansible.posix                 1.3.0  
ansible.utils                 2.6.1  
ansible.windows               1.10.0 
arista.eos                    3.1.0  
awx.awx                       19.4.0 
azure.azcollection            1.12.0 
check_point.mgmt              2.3.0  
chocolatey.chocolatey         1.2.0  
cisco.aci                     2.2.0  
cisco.asa                     2.1.0  
cisco.intersight              1.0.18 
cisco.ios                     2.8.1  
cisco.iosxr                   2.9.0  
cisco.ise                     1.2.1  
cisco.meraki                  2.6.2  
cisco.mso                     1.4.0  
cisco.nso                     1.0.3  
cisco.nxos                    2.9.1  
cisco.ucs                     1.8.0  
cloud.common                  2.1.1  
cloudscale_ch.cloud           2.2.1  
community.aws                 2.4.0  
community.azure               1.1.0  
community.ciscosmb            1.0.5  
community.crypto              2.3.1  
community.digitalocean        1.19.0 
community.dns                 2.1.1  
community.docker              2.5.1  
community.fortios             1.0.0  
community.general             4.8.1  
community.google              1.0.0  
community.grafana             1.4.0  
community.hashi_vault         2.5.0  
community.hrobot              1.3.0  
community.kubernetes          2.0.1  
community.kubevirt            1.0.0  
community.libvirt             1.1.0  
community.mongodb             1.4.0  
community.mysql               2.3.7  
community.network             3.3.0  
community.okd                 2.2.0  
community.postgresql          1.7.4  
community.proxysql            1.3.2  
community.rabbitmq            1.2.1  
community.routeros            2.0.0  
community.sap                 1.0.0  
community.skydive             1.0.0  
community.sops                1.2.1  
community.vmware              1.18.0 
community.windows             1.10.0 
community.zabbix              1.6.0  
containers.podman             1.9.3  
cyberark.conjur               1.1.0  
cyberark.pas                  1.0.13 
dellemc.enterprise_sonic      1.1.0  
dellemc.openmanage            4.4.0  
dellemc.os10                  1.1.1  
dellemc.os6                   1.0.7  
dellemc.os9                   1.0.4  
f5networks.f5_modules         1.16.0 
fortinet.fortimanager         2.1.5  
fortinet.fortios              2.1.4  
frr.frr                       1.0.4  
gluster.gluster               1.0.2  
google.cloud                  1.0.2  
hetzner.hcloud                1.6.0  
hpe.nimble                    1.1.4  
ibm.qradar                    1.0.3  
infinidat.infinibox           1.3.3  
infoblox.nios_modules         1.2.1  
inspur.sm                     1.3.0  
junipernetworks.junos         2.10.0 
kubernetes.core               2.3.1  
mellanox.onyx                 1.0.0  
netapp.aws                    21.7.0 
netapp.azure                  21.10.0
netapp.cloudmanager           21.17.0
netapp.elementsw              21.7.0 
netapp.ontap                  21.19.1
netapp.storagegrid            21.10.0
netapp.um_info                21.8.0 
netapp_eseries.santricity     1.3.0  
netbox.netbox                 3.7.1  
ngine_io.cloudstack           2.2.3  
ngine_io.exoscale             1.0.0  
ngine_io.vultr                1.1.1  
openstack.cloud               1.8.0  
openvswitch.openvswitch       2.1.0  
ovirt.ovirt                   1.6.6  
purestorage.flasharray        1.13.0 
purestorage.flashblade        1.9.0  
sensu.sensu_go                1.13.1 
servicenow.servicenow         1.0.6  
splunk.es                     1.0.2  
t_systems_mms.icinga_director 1.29.0 
theforeman.foreman            2.2.0  
vmware.vmware_rest            2.1.5  
vyos.vyos                     2.8.0  
wti.remote                    1.0.3  
CONFIGURATION
ansible-playbook [core 2.12.6]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.7 (default, Nov 24 2021, 21:15:59) [GCC 10.3.1 20211027]
  jinja version = 3.1.2
  libyaml = False
OS / ENVIRONMENT

Target OS: windows Server 2016 Datacentre image

STEPS TO REPRODUCE

ansible-playbook -i ./inventory -l ${HOSTS_TAG} ./playbook.yml --extra-vars "ansible_sudo_pass=${APP11755_TEST_SUDO_PASS}" --extra-vars="ansible_become_pass=${APP11755_TEST_SUDO_PASS}" -vvv

---
- hosts: all
   strategy: free

  tasks:   
   - name: Test connectivity to a windows host
    win_ping:

- name: Pre Check for Security Updates
    win_updates:
      category_names: SecurityUpdates
      state: searched
      log_path: C:\temp\ansible_patch_fetch.log
    register: precheck_state
EXPECTED RESULTS
ACTUAL RESULTS
$ ansible-galaxy collection install ansible.windows
[WARNING]: Ansible is being run in a world writable directory
(/builds/SRE/ansible/app11755/test/ukb-agent-online-windows-facts), ignoring it
as an ansible.cfg source. For more information see
https://docs.ansible.com/ansible/devel/reference_appendices/config.html#cfg-in-
world-writable-dir
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/download/ansible-windows-1.12.0.tar.gz to /root/.ansible/tmp/ansible-local-29qu5yce3g/tmpz72192rd/ansible-windows-1.12.0-n474fbfx
Installing 'ansible.windows:1.12.0' to '/root/.ansible/collections/ansible_collections/ansible/windows'
ansible.windows:1.12.0 was installed successfully
$ ansible-playbook -i ./inventory -l ${HOSTS_TAG} ./playbook.yml --extra-vars "ansible_sudo_pass=${APP11755_TEST_SUDO_PASS}" --extra-vars="ansible_become_pass=${APP11755_TEST_SUDO_PASS}" -vvv

<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": {}
}
phess commented 1 year ago

I'm also facing the same error: it fails on line 483 of plugins/modules/win_updates.ps1 as well, inside InvokeAsBatchLogon. I have zero knowledge of powershell but the condition triggering this error looks race-y in my utterly unexperienced eyes.

jborean93 commented 1 year ago

@phess do you know if your scenario is also using become? Is it repeatable or does it occur randomly? Trying to find some common patterns so I can try and replicate the error and track down what might be happening.

jborean93 commented 1 year ago

I've opened a PR https://github.com/ansible-collections/ansible.windows/pull/495 which rewrites the batch script runner into something with less moving parts. Even if it doesn't solve the problem for you it should at least provide more detailed information on a failure hopefully indicating what the actual problem was.