Remove last characters(.zip) from listed output llines in windows ansible

Hi all,

I wanted to remove the .zip from output line in the ansible from below;

“result.stdout_lines”: [
“Database_0.0.100.zip”,
“EMC_ECS-package_0.0.100.zip”,
“hotfix-DDMInfra.zip”,
“hotfix-IIS.zip”,
“hotfix-QCIM1H126382-v3.zip”,
“MMiS_Offering_0.0.108.zip”,
“Network_v_0.0.100.zip”,
“NormalizationRules_100.zip”,
“UDAgentManagement_10.33.0.zip”,
“UDI_Data_Model_0.0.104.zip”,
“UDI_Discovery_Administration_100.zip”,
“UDI_Discovery_Base_Enrichment_0.0.105.zip”,
“UDI_TenantAssociationRules_100.zip”,
“WebService_0.0.103.zip”,
“XCDE_Outbound_Adapter_0.0.101.zip”

for remove .zip I added task as below:

  • debug: msg=“{{ result.stdout_lines[0:-2] }}”
    with_items:
  • “{{ result.stdout_lines }}”

but output is remove the “XCDE_Outbound_Adapter_0.0.101.zip” and “WebService_0.0.103.zip”, not .zip

Could you please let me know how to remove the .zip from each line?
the expected output should be;
" Database_0.0.100",
“EMC_ECS-package_0.0.100”,
“hotfix-DDMInfra”,
“hotfix-IIS.zip”,
“hotfix-QCIM1H126382-v3”, …etc…

Best regards,
Venkat

This debug probably fix the problem

    - debug:
        msg: "{{ item[:-4] }}"
      loop: "{{ result.stdout_lines }}"

, but to get the modified list use this

    - set_fact:
        my_list: "{{ result.stdout_lines|
                     map('regex_replace', regex, replace)|
                     list }}"
      vars:
        regex: '(.*?)(\.zip)?'
        replace: '\1'

Cheers,

  -vlado