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

Need to preserve URL escaped characters in downloaded file #429

Open opoplawski opened 2 years ago

opoplawski commented 2 years ago
SUMMARY

BitDefender setupdownloader depends on the filename remaining exactly the same. But it contains '[' and ']' characters that end up URL escaped in the downloaded file.

ISSUE TYPE
COMPONENT NAME

win_package

ANSIBLE VERSION
ansible [core 2.12.2]
  config file = /home/orion-admin/ansible-windows/ansible.cfg
  configured module search path = ['/home/orion-admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.8/site-packages/ansible
  ansible collection location = /home/orion-admin/ansible-windows:/home/orion-admin/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.8.12 (default, Sep 16 2021, 10:46:05) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 2.10.3
  libyaml = True
COLLECTION VERSION
# /usr/share/ansible/collections/ansible_collections
Collection      Version
--------------- -------
ansible.windows 1.10.0

# /home/orion-admin/ansible-windows/ansible_collections
Collection      Version
--------------- -------
ansible.windows 1.11.1
CONFIGURATION
COLLECTIONS_PATHS(/home/orion-admin/ansible-windows/ansible.cfg) = ['/home/orion-admin/ansible-win>
DEFAULT_FORKS(/home/orion-admin/ansible-windows/ansible.cfg) = 25
DEFAULT_GATHERING(/home/orion-admin/ansible-windows/ansible.cfg) = explicit
DEFAULT_HOST_LIST(/home/orion-admin/ansible-windows/ansible.cfg) = ['/home/orion-admin/ansible-win>
DEFAULT_INVENTORY_PLUGIN_PATH(/home/orion-admin/ansible-windows/ansible.cfg) = ['/home/orion-admin>
DEFAULT_JINJA2_EXTENSIONS(/home/orion-admin/ansible-windows/ansible.cfg) = jinja2.ext.do
DEFAULT_ROLES_PATH(/home/orion-admin/ansible-windows/ansible.cfg) = ['/home/orion-admin/ansible-wi>
DEFAULT_STRATEGY(/home/orion-admin/ansible-windows/ansible.cfg) = mitogen_linear
DEFAULT_STRATEGY_PLUGIN_PATH(/home/orion-admin/ansible-windows/ansible.cfg) = ['/home/orion-admin/>
DEFAULT_TIMEOUT(/home/orion-admin/ansible-windows/ansible.cfg) = 20
PERSISTENT_CONNECT_TIMEOUT(/home/orion-admin/ansible-windows/ansible.cfg) = 30
RETRY_FILES_ENABLED(/home/orion-admin/ansible-windows/ansible.cfg) = False
OS / ENVIRONMENT

RHEL 8.6

STEPS TO REPRODUCE
  tasks:
    - name: Install BitDefender
# This URL escapes the filename which breaks install
      ansible.windows.win_package:
        path: "https://grav1.nwra.com/Packages/BSTWIN/0/setupdownloader_[aHR0cHM6Ly9ncmF2MS5ud3JhLmNvbTo4NDQzL1BhY2thZ2VzL0JTVFdJTi8wL2FxOTBmbC9pbnN0YWxsZXIueG1sP2xhbmc9ZW4tVVM=].exe"
        product_id: Endpoint Security
        arguments: /bdparams /silent silent
        state: present
EXPECTED RESULTS

Install succeeds

ACTUAL RESULTS
TASK [Install BitDefender] ************************************************************************
task path: /home/orion-admin/ansible-windows/install-bitdefender-package.yml:6
fatal: [prn-bld01.ad.nwra.com]: FAILED! => {"changed": false, "elapsed": 3.0165842, "msg": "unexpected rc from 'C:\\Users\\orion-admin\\AppData\\Local\\Temp\\ansible-moduletmp-133108513167669159-771566920\\setupdownloader_%5BaHR0cHM6Ly9ncmF2MS5ud3JhLmNvbTo4NDQzL1BhY2thZ2VzL0JTVFdJTi8wL2FxOTBmbC9pbnN0YWxsZXIueG1sP2xhbmc9ZW4tVVM=%5D.exe /bdparams /silent silent': see rc, stdout, and stderr for more details", "rc": 3, "reboot_required": false, "status_code": 200, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
jborean93 commented 2 years ago

This might be hard to achieve, we currently use the response URL segment to derive the file name as per https://github.com/ansible-collections/ansible.windows/blob/da837ec87f78d7af3467ead65e1f934f44798a4b/plugins/modules/win_package.ps1#L508. At this point in time the URL has already been changed by dotnet. We could use [Uri]::UnescapeDataString(...) to get the raw value back but I'm unsure whether this might cause more problems down the line with invalid file path characters.

As a workaround for now you can use win_get_url to download the package manually with the chars you filename needed until we figure out the best way forward here.