From f78a44c6a383d8ee523524f4ead47f4dce245cfb Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 15 Apr 2026 22:01:19 +0200 Subject: [PATCH] [PR #11825/d1448b76 backport][stable-12] iso_extract: strip leading path separator from file entries (#11832) iso_extract: strip leading path separator from file entries (#11825) * iso_extract: strip leading path separator from file entries Fixes #5283 * iso_extract: add changelog fragment for issue 5283 --------- (cherry picked from commit d1448b76c11f8b5dd3eef2b0ce1beae5fc1c4f63) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 --- .../11825-iso-extract-leading-slash.yml | 2 ++ plugins/modules/iso_extract.py | 5 +++-- .../targets/iso_extract/tasks/tests.yml | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/11825-iso-extract-leading-slash.yml diff --git a/changelogs/fragments/11825-iso-extract-leading-slash.yml b/changelogs/fragments/11825-iso-extract-leading-slash.yml new file mode 100644 index 0000000000..1b656f8709 --- /dev/null +++ b/changelogs/fragments/11825-iso-extract-leading-slash.yml @@ -0,0 +1,2 @@ +bugfixes: + - iso_extract - strip leading path separator from file entries so files with a leading ``/`` are extracted correctly (https://github.com/ansible-collections/community.general/issues/5283, https://github.com/ansible-collections/community.general/pull/11825). diff --git a/plugins/modules/iso_extract.py b/plugins/modules/iso_extract.py index 2fd807d15c..42d483dbeb 100644 --- a/plugins/modules/iso_extract.py +++ b/plugins/modules/iso_extract.py @@ -48,6 +48,7 @@ options: description: - A list of files to extract from the image. - Extracting directories does not work. + - File paths should not include a leading V(/); any leading path separator is automatically stripped. type: list elements: str required: true @@ -138,11 +139,11 @@ def main(): module.fail_json(msg=f"ISO image '{image}' does not exist") result["files"] = [] - extract_files = list(files) + extract_files = [f.lstrip(os.sep) for f in files] if not force: # Check if we have to process any files based on existence - for f in files: + for f in extract_files[:]: dest_file = os.path.join(dest, os.path.basename(f)) if os.path.exists(dest_file): result["files"].append( diff --git a/tests/integration/targets/iso_extract/tasks/tests.yml b/tests/integration/targets/iso_extract/tasks/tests.yml index 8e37cda024..bc55fc7736 100644 --- a/tests/integration/targets/iso_extract/tasks/tests.yml +++ b/tests/integration/targets/iso_extract/tasks/tests.yml @@ -38,3 +38,19 @@ that: - iso_extract_test0_again is changed when: in_check_mode + +- name: Extract the iso using files with leading slash + iso_extract: + image: '{{ output_test_dir }}/test.iso' + dest: '{{ output_test_dir }}' + files: + - /1.txt + - /2.txt + force: true + register: iso_extract_leading_slash + +- name: Test iso_extract with leading slash succeeds (normal mode) + assert: + that: + - iso_extract_leading_slash is not failed + when: not in_check_mode