ansible-collections / community.aws

Ansible Collection for Community AWS
GNU General Public License v3.0
186 stars 394 forks source link

aws_ssm connection plugin - Windows Update Invalid Literal For Int #1751

Open offlineadmin opened 1 year ago

offlineadmin commented 1 year ago

Summary

I am attempting to run ansible.windows.win_updates on a Windows 2019 EC2 instance using the ssm connection plugin. When I do so, I get:

The full traceback is:
Traceback (most recent call last):
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 761, in run
    result = self._run_sync(task_vars, module_options, reboot, reboot_timeout)
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 834, in _run_sync
    update_result = self._run_updates(task_vars, module_options, poll_script_path, cancel_script_path)
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 915, in _run_updates
    entries, offset = self._poll_result(poll_script_path, output_path, offset)
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 964, in _poll_result
    offset = int(lines.pop(-1))
ValueError: invalid literal for int() with base 10: '{"task":"search_result","result":{"updates":[{"impact":"Normal","categories":["Security Updates"],"revision_number":1,"auto_download":"AlwaysAutoDownload","deployment_action":"Installation","descript
fatal: [PatchyTheMagicDragon]: 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": [
                "*"
            ],
            "log_path": "C:\\ansible_wu.txt",
            "reboot": true,
            "reboot_timeout": 1200,
            "reject_list": null,
            "server_selection": "default",
            "skip_optional": false,
            "state": "installed",
            "use_scheduled_task": false
        }
    },
    "msg": "invalid literal for int() with base 10: '{\"task\":\"search_result\",\"result\":{\"updates\":[{\"impact\":\"Normal\",\"categories\":[\"Security Updates\"],\"revision_number\":1,\"auto_download\":\"AlwaysAutoDownload\",\"deployment_action\":\"Installation\",\"descript",
    "updates": []
}

Issue Type

Bug Report

Component Name

aws_ssm.py

Ansible Version

ansible [core 2.11.12]
  config file = None
  configured module search path = ['/home/ec2-user/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ec2-user/ansible/lib64/python3.7/site-packages/ansible
  ansible collection location = /home/ec2-user/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/ec2-user/ansible/bin/ansible
  python version = 3.7.16 (default, Dec 15 2022, 23:24:54) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]
  jinja version = 3.1.2
  libyaml = True

Collection Versions

# /home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.1
ansible.netcommon             2.5.0
ansible.posix                 1.3.0
ansible.utils                 2.4.3
ansible.windows               1.8.0
arista.eos                    2.2.0
awx.awx                       19.4.0
azure.azcollection            1.10.0
check_point.mgmt              2.2.0
chocolatey.chocolatey         1.1.0
cisco.aci                     2.1.0
cisco.asa                     2.1.0
cisco.intersight              1.0.18
cisco.ios                     2.6.0
cisco.iosxr                   2.6.0
cisco.meraki                  2.5.0
cisco.mso                     1.2.0
cisco.nso                     1.0.3
cisco.nxos                    2.8.2
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.2.0
community.aws                 1.5.0
community.azure               1.1.0
community.crypto              1.9.8
community.digitalocean        1.13.0
community.docker              1.10.2
community.fortios             1.0.0
community.general             3.8.3
community.google              1.0.0
community.grafana             1.3.0
community.hashi_vault         1.5.0
community.hrobot              1.2.1
community.kubernetes          1.2.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.2
community.mysql               2.3.2
community.network             3.0.0
community.okd                 1.1.2
community.postgresql          1.6.0
community.proxysql            1.3.0
community.rabbitmq            1.1.0
community.routeros            1.2.0
community.skydive             1.0.0
community.sops                1.2.0
community.vmware              1.17.0
community.windows             1.8.0
community.zabbix              1.5.1
containers.podman             1.9.0
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            3.6.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.13.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.3
frr.frr                       1.0.3
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.0
inspur.sm                     1.3.0
junipernetworks.junos         2.8.0
kubernetes.core               1.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.1
netapp.elementsw              21.7.0
netapp.ontap                  21.14.1
netapp.um_info                21.8.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.4.0
ngine_io.cloudstack           2.2.2
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.5.3
openvswitch.openvswitch       2.1.0
ovirt.ovirt                   1.6.6
purestorage.flasharray        1.11.0
purestorage.flashblade        1.8.1
sensu.sensu_go                1.12.0
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.26.0
theforeman.foreman            2.2.0
vyos.vyos                     2.6.0
wti.remote                    1.0.3

# /home/ec2-user/.ansible/collections/ansible_collections
Collection    Version
------------- -------
amazon.aws    5.3.0
community.aws 5.3.0

# /home/ec2-user/ansible/lib/python3.7/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.1
ansible.netcommon             2.5.0
ansible.posix                 1.3.0
ansible.utils                 2.4.3
ansible.windows               1.8.0
arista.eos                    2.2.0
awx.awx                       19.4.0
azure.azcollection            1.10.0
check_point.mgmt              2.2.0
chocolatey.chocolatey         1.1.0
cisco.aci                     2.1.0
cisco.asa                     2.1.0
cisco.intersight              1.0.18
cisco.ios                     2.6.0
cisco.iosxr                   2.6.0
cisco.meraki                  2.5.0
cisco.mso                     1.2.0
cisco.nso                     1.0.3
cisco.nxos                    2.8.2
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.2.0
community.aws                 1.5.0
community.azure               1.1.0
community.crypto              1.9.8
community.digitalocean        1.13.0
community.docker              1.10.2
community.fortios             1.0.0
community.general             3.8.3
community.google              1.0.0
community.grafana             1.3.0
community.hashi_vault         1.5.0
community.hrobot              1.2.1
community.kubernetes          1.2.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.2
community.mysql               2.3.2
community.network             3.0.0
community.okd                 1.1.2
community.postgresql          1.6.0
community.proxysql            1.3.0
community.rabbitmq            1.1.0
community.routeros            1.2.0
community.skydive             1.0.0
community.sops                1.2.0
community.vmware              1.17.0
community.windows             1.8.0
community.zabbix              1.5.1
containers.podman             1.9.0
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            3.6.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.13.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.3
frr.frr                       1.0.3
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.0
inspur.sm                     1.3.0
junipernetworks.junos         2.8.0
kubernetes.core               1.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.1
netapp.elementsw              21.7.0
netapp.ontap                  21.14.1
netapp.um_info                21.8.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.4.0
ngine_io.cloudstack           2.2.2
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.5.3
openvswitch.openvswitch       2.1.0
ovirt.ovirt                   1.6.6
purestorage.flasharray        1.11.0
purestorage.flashblade        1.8.1
sensu.sensu_go                1.12.0
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.26.0
theforeman.foreman            2.2.0
vyos.vyos                     2.6.0
wti.remote                    1.0.3

AWS SDK versions

WARNING: Package(s) not found: boto
Name: boto3
Version: 1.26.93
Summary: The AWS SDK for Python
Home-page: https://github.com/boto/boto3
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /home/ec2-user/ansible/lib/python3.7/site-packages
Requires: botocore, jmespath, s3transfer
Required-by:
---
Name: botocore
Version: 1.29.93
Summary: Low-level, data-driven core of boto 3.
Home-page: https://github.com/boto/botocore
Author: Amazon Web Services
Author-email:
License: Apache License 2.0
Location: /home/ec2-user/ansible/lib/python3.7/site-packages
Requires: jmespath, python-dateutil, urllib3
Required-by: boto3, s3transfer

Configuration

No output

OS / Environment

Amazon Linux 2 ansible workstation Windows Server 2019 target host

Steps to Reproduce

- name: Patching | Windows - Install All Updates
          ansible.windows.win_updates:
            category_names: '*'
            reboot: yes
            log_path: C:\ansible_wu.txt
          when: ansible_facts['os_family'] == "Windows"

Expected Results

I expect the machine to patch

Actual Results

The task fails:

The full traceback is:
Traceback (most recent call last):
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 761, in run
    result = self._run_sync(task_vars, module_options, reboot, reboot_timeout)
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 834, in _run_sync
    update_result = self._run_updates(task_vars, module_options, poll_script_path, cancel_script_path)
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 915, in _run_updates
    entries, offset = self._poll_result(poll_script_path, output_path, offset)
  File "/home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections/ansible/windows/plugins/action/win_updates.py", line 964, in _poll_result
    offset = int(lines.pop(-1))
ValueError: invalid literal for int() with base 10: '{"task":"search_result","result":{"updates":[{"impact":"Normal","categories":["Security Updates"],"revision_number":1,"auto_download":"AlwaysAutoDownload","deployment_action":"Installation","descript
fatal: [PatchyTheMagicDragon]: 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": [
                "*"
            ],
            "log_path": "C:\\ansible_wu.txt",
            "reboot": true,
            "reboot_timeout": 1200,
            "reject_list": null,
            "server_selection": "default",
            "skip_optional": false,
            "state": "installed",
            "use_scheduled_task": false
        }
    },
    "msg": "invalid literal for int() with base 10: '{\"task\":\"search_result\",\"result\":{\"updates\":[{\"impact\":\"Normal\",\"categories\":[\"Security Updates\"],\"revision_number\":1,\"auto_download\":\"AlwaysAutoDownload\",\"deployment_action\":\"Installation\",\"descript",
    "updates": []
}

Code of Conduct

offlineadmin commented 1 year ago

I thought it would be important to include the vars for the target host as well as the fact that the connection module is working as expected on all our Linux distros and on other Windows tasks.

acctXXXXXXXXXXXX: hosts: PatchyTheMagicDragon: ansible_aws_ssm_bucket_name: ssm-XXXXXXXXXXXX ansible_aws_ssm_region: us-east-1 ansible_connection: community.aws.aws_ssm ansible_host: i-XXXXXXXXXXXXXXXXX ansible_shell_type: powershell

tremble commented 1 year ago

This looks a lot like https://github.com/ansible-collections/community.aws/issues/113 which has been fixed.

You currently have 3 copies of the plugin installed.

community.aws                 1.5.0
...
community.aws 5.3.0
...
community.aws                 1.5.0

Please try uninstalling the old copies of the plugin, I suspect one of the 1.5.0 copies is being used rather than 5.3.0.

offlineadmin commented 1 year ago

Same error. Here's the ansible-galaxy collection list output after the changes:

# /home/ec2-user/ansible/lib/python3.7/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
ansible.netcommon             2.5.0
ansible.posix                 1.3.0
ansible.utils                 2.4.3
ansible.windows               1.8.0
arista.eos                    2.2.0
awx.awx                       19.4.0
azure.azcollection            1.10.0
check_point.mgmt              2.2.0
chocolatey.chocolatey         1.1.0
cisco.aci                     2.1.0
cisco.asa                     2.1.0
cisco.intersight              1.0.18
cisco.ios                     2.6.0
cisco.iosxr                   2.6.0
cisco.meraki                  2.5.0
cisco.mso                     1.2.0
cisco.nso                     1.0.3
cisco.nxos                    2.8.2
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.2.0
community.azure               1.1.0
community.crypto              1.9.8
community.digitalocean        1.13.0
community.docker              1.10.2
community.fortios             1.0.0
community.general             3.8.3
community.google              1.0.0
community.grafana             1.3.0
community.hashi_vault         1.5.0
community.hrobot              1.2.1
community.kubernetes          1.2.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.2
community.mysql               2.3.2
community.network             3.0.0
community.okd                 1.1.2
community.postgresql          1.6.0
community.proxysql            1.3.0
community.rabbitmq            1.1.0
community.routeros            1.2.0
community.skydive             1.0.0
community.sops                1.2.0
community.vmware              1.17.0
community.windows             1.8.0
community.zabbix              1.5.1
containers.podman             1.9.0
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            3.6.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.13.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.3
frr.frr                       1.0.3
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.0
inspur.sm                     1.3.0
junipernetworks.junos         2.8.0
kubernetes.core               1.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.1
netapp.elementsw              21.7.0
netapp.ontap                  21.14.1
netapp.um_info                21.8.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.4.0
ngine_io.cloudstack           2.2.2
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.5.3
openvswitch.openvswitch       2.1.0
ovirt.ovirt                   1.6.6
purestorage.flasharray        1.11.0
purestorage.flashblade        1.8.1
sensu.sensu_go                1.12.0
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.26.0
theforeman.foreman            2.2.0
vyos.vyos                     2.6.0
wti.remote                    1.0.3

# /home/ec2-user/ansible/lib64/python3.7/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
ansible.netcommon             2.5.0
ansible.posix                 1.3.0
ansible.utils                 2.4.3
ansible.windows               1.8.0
arista.eos                    2.2.0
awx.awx                       19.4.0
azure.azcollection            1.10.0
check_point.mgmt              2.2.0
chocolatey.chocolatey         1.1.0
cisco.aci                     2.1.0
cisco.asa                     2.1.0
cisco.intersight              1.0.18
cisco.ios                     2.6.0
cisco.iosxr                   2.6.0
cisco.meraki                  2.5.0
cisco.mso                     1.2.0
cisco.nso                     1.0.3
cisco.nxos                    2.8.2
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.2.0
community.azure               1.1.0
community.crypto              1.9.8
community.digitalocean        1.13.0
community.docker              1.10.2
community.fortios             1.0.0
community.general             3.8.3
community.google              1.0.0
community.grafana             1.3.0
community.hashi_vault         1.5.0
community.hrobot              1.2.1
community.kubernetes          1.2.1
community.kubevirt            1.0.0
community.libvirt             1.0.2
community.mongodb             1.3.2
community.mysql               2.3.2
community.network             3.0.0
community.okd                 1.1.2
community.postgresql          1.6.0
community.proxysql            1.3.0
community.rabbitmq            1.1.0
community.routeros            1.2.0
community.skydive             1.0.0
community.sops                1.2.0
community.vmware              1.17.0
community.windows             1.8.0
community.zabbix              1.5.1
containers.podman             1.9.0
cyberark.conjur               1.1.0
cyberark.pas                  1.0.13
dellemc.enterprise_sonic      1.1.0
dellemc.openmanage            3.6.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.13.0
fortinet.fortimanager         2.1.4
fortinet.fortios              2.1.3
frr.frr                       1.0.3
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.0
inspur.sm                     1.3.0
junipernetworks.junos         2.8.0
kubernetes.core               1.2.1
mellanox.onyx                 1.0.0
netapp.aws                    21.7.0
netapp.azure                  21.10.0
netapp.cloudmanager           21.12.1
netapp.elementsw              21.7.0
netapp.ontap                  21.14.1
netapp.um_info                21.8.0
netapp_eseries.santricity     1.2.13
netbox.netbox                 3.4.0
ngine_io.cloudstack           2.2.2
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.5.3
openvswitch.openvswitch       2.1.0
ovirt.ovirt                   1.6.6
purestorage.flasharray        1.11.0
purestorage.flashblade        1.8.1
sensu.sensu_go                1.12.0
servicenow.servicenow         1.0.6
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.26.0
theforeman.foreman            2.2.0
vyos.vyos                     2.6.0
wti.remote                    1.0.3

# /home/ec2-user/.ansible/collections/ansible_collections
Collection    Version
------------- -------
amazon.aws    5.3.0
community.aws 5.3.0
tremble commented 1 year ago

In that case, please include the output when running ansible-playbook adding the -vvvvv option. This should be very verbose but also includes a lot of debugging information which shows what's going on.

tremble commented 1 year ago

We also had a report (#1725) which seems to imply things don't behave properly when the "host" (Windows machine) has an old version of the SSM Client installed.

offlineadmin commented 1 year ago

SSM version is 3.2.582.0 which is latest I'll have the debug data up in a minute

offlineadmin commented 1 year ago

I'm not allowed to post all this encoded data on a public forum. Are there any particular snippets you're looking for that I could sanitize and post?

tremble commented 1 year ago

The first thing I'm looking for is the format of the logging (some of this changed in 5.2), since there were multiple copies lurking I just want to double check that we're using the copy we think we are.

Since the action's trying to pop the final line, I'd guess data's either being truncated, or isn't being split properly by "splitlines". But since I'm not familiar with the ansible.windows collection I'm not sure what data it's actually expecting to see. The code that's throwing an error can be found at https://github.com/ansible-collections/ansible.windows/blob/main/plugins/action/win_updates.py#L978

The code that's processing the output of the "host" side plugin before it gets passed back to the action is https://github.com/ansible-collections/community.aws/blob/stable-5/plugins/connection/aws_ssm.py#L522