8000 mirror_ocp_release: fixes for concurrent jobs by nsilla · Pull Request #626 · redhatci/ansible-collection-redhatci-ocp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

mirror_ocp_release: fixes for concurrent jobs #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nsilla
Copy link
Contributor
@nsilla nsilla commented Apr 1, 2025
SUMMARY

Fixes CILAB-2034: when multiple jobs run to mirror the same version on the same host, the status of the mirroring directory may be unstable depending on the order the tasks are run on each job.

This change implements temporary directories per role call so the artifacts are only moved to the final location at the end of the execution.

ISSUE TYPE
  • Bug
Tests

TestBos2Sno: sno sno:components=ocp=4.18.5,

Summary by CodeRabbit

  • Refactor

    • Improved reliability and maintainability of artifact extraction and file operations by using a temporary workspace and consolidating file copy and permission steps.
    • Unified and clarified variable naming and data handling for release and image metadata across tasks.
    • Enhanced task consistency by standardizing variable names and result registration.
    • Streamlined command formatting and improved conditional logic for registry operations.
  • Bug Fixes

    • Corrected variable references for container image sources to ensure accurate data usage.

@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

10000
@@ -11,20 +11,26 @@
when:
- mor_force or not _mor_target.stat.exists
block:
- name: "Extract installer and metadata from release image"
ansible.builtin.shell: >
flock -x {{ mor_cache_dir }}/{{ mor_version }}/release_extract.lock -c '
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this new approach, use of filesystem locks is not needed anymore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered scenarios where two jobs run concurrently, both extracting to a temporary location and writing to mor_cache_dir? How do you prevent conflicts in such cases? Implementing a mechanism like a lock might help avoid these issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a fair point. I was accepting the risk of facing such scenarios provided moving files around the filesystem is must faster than running the operations directly on the mor_cache_dir.

But at this point it's right what we could just limit the protected zone to the task were we copy the files to the cache directory once they have been processed in the temporary directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here comes another thought. The way this implementation works, the problematic task would be when we run the copy module to move the files from the temporary directory to the cache directory. Alternatively or in combination of the lock usage, we can add the parameter "force: false" to the module call, so ansible won't replace a file that already exists, even if the contents are different.
The question here is whether it'd be safe to assume the artifact won't change between jobs deploying the same OCP release.
My guess is the files won't change if the jobs are running concurrently, but would those artifacts change between jobs running with, say, days of difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I don't find a way of implementing locks that would allows us to run ansible tasks in the locked zone.

In other words, when using locks the lock code must be part of the same shell script.

{{ mor_oc }} adm release extract
--registry-config {{ mor_auths_file }}
--command={{ mor_installer }}
--from {{ mor_pull_url }}
--to "{{ mor_cache_dir }}/{{ mor_version }}";
--to "{{ _mor_tmp.path }}";
Copy link
Contributor < 8000 span aria-label="This user is the author of this pull request." data-view-component="true" class="tooltipped tooltipped-n"> Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artifacts are first extracted into the temporary directory for the job.

get_checksum: false
register: target
when:
- not mor_force
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're extracting the artifacts on a temporary directory, the file won't exist in advance.

Copy link

- name: Copy artifacts to release directory
ansible.builtin.copy:
src: "{{ _mor_tmp.path }}/"
dest: "{{ mor_cache_dir }}/{{ mor_version }}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the end of the job execution the artifacts are copied to the job's target directory. For this, we use a regular task at the end of the role instead of handlers, so we don't wait for the end of the play to copy the artifacts.

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 7e5d9f5 to e7675e7 Compare April 1, 2025 10:15
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

state: directory
prefix: mor-
register: _mor_tmp
notify: "Remove temporary directory"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use a handler to remove the temporary directory so we make sure it's run at the end of the play.

The goal is to have it running on successful and failed jobs. For this to work, the play calling this role must activate the flag "force_handlers: true", otherwise the handler will only be run on success.

We chose this approach to a block with an "always" section, so we don't need to add extra tasks to track the failed step properly.

Copy link

@nsilla nsilla force-pushed the concurrent_release_mirror branch from e7675e7 to 903f001 Compare April 1, 2025 10:21
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

@@ -35,4 +27,5 @@
ansible.builtin.command: /usr/sbin/restorecon -R "{{ mor_dir }}/{{ mor_uri | basename }}"
become: true
when: _mor_selinux.rc == 0
# we may need to run this task over the target directory rather than mor_dir (= _mor_tmp.path)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the original scenario, the artifacts are extracted into an httpd served directory, so restoring the contexts is needed for the files to be properly served. Restoring the contexts on the temporary directory may not have any effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the next tasks in the artifacts.yml file after including the fetch.yml set new the new context container_file_t on the extracted artifacts. This I assume is done from here so it'll be applied to both, OCP versions greater or equal than 4.8 and lower than 4.8. But that means the tasks in fetch.yml are not needed.

Copy link

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 903f001 to 11767d3 Compare April 1, 2025 10:29
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

- name: "Apply new SELinux file context to file"
ansible.builtin.command: /usr/sbin/restorecon -R "{{ mor_dir }}/{{ mor_uri | basename }}"
become: true
when: _mor_selinux.rc == 0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restoring the selinux context does not make sense when extracting the artifacts on a temporary directory.
Also, the first tasks in artifacts.yml after including fetch.yml override the context and set it to container_file_t, which should be valid even after moving the artifacts to the target directory served from the cache container.
A different discussion is whether these tasks should be run before or after copying the artifacts to the target directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to restore this block of code, since fetch.yml is also included from images.yml to pull the disk image directly into the cache store (version directory ignored) so then it's directly served by the cache container.

Copy link

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 11767d3 to 4995c13 Compare April 1, 2025 10:35
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 4995c13 to 13e17c5 Compare April 1, 2025 10:36
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

1 similar comment
@dcibot
Copy link
Collaborator
dcibot commented Apr 1, 2025

from change #626:

  • no check (not a code change)

Copy link

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 13e17c5 to bd32593 Compare April 1, 2025 13:24
@nsilla nsilla force-pushed the concurrent_release_mirror branch 2 times, most recently from 19e8084 to b3dc5c9 Compare April 4, 2025 08:34
@nsilla nsilla requested a review from betoredhat April 4, 2025 08:35
@nsilla nsilla marked this pull request as ready for review April 4, 2025 08:35
@nsilla nsilla requested a review from a team as a code owner April 4, 2025 08:35
@dcibot
Copy link
Collaborator
dcibot commented Apr 4, 2025

Copy link

@nsilla nsilla force-pushed the concurrent_release_mirror branch from b3dc5c9 to 89d08c8 Compare April 7, 2025 10:14
@dcibot
Copy link
Collaborator
dcibot commented Apr 7, 2025

Copy link

src: "{{ _mor_tmp.path }}/"
dest: "{{ mor_cache_dir }}/{{ mor_version }}/"
mode: preserve
force: false
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By setting the "force" parameter to "false" we prevent the module to get a file into an inconsistent state if the file already exists.
This is interesting, for instance, to prevent binary execution exceptions if modification of the binary file are detected during the execution.
There are some concerns regarding this approach, though:

  • if force is set to true, existing files are only replaced if changed, which should not happen between files belonging in the same release number.
  • since Ansible copy module uses atomic moves, the target file path should not suffer hash code changes during the copy process, so it shouldn't be possible for Ansible to mark a file as replaceable just because it's content is in an unstable state yet.
  • thus, the force: false option is only an extra precaution we take.
  • this feature would prevent files to be updated if they suffer any modification even within the same ocp release number.

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 89d08c8 to 355027e Compare April 7, 2025 13:21
Copy link

@dcibot
Copy link
Collaborator
dcibot commented Apr 7, 2025

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 355027e to ceeec63 Compare April 7, 2025 13:27
Copy link

@dcibot
Copy link
Collaborator
dcibot commented Apr 7, 2025

@nsilla nsilla force-pushed the concurrent_release_mirror branch from ceeec63 to 33a30f4 Compare April 7, 2025 13:31
@dcibot
Copy link
Collaborator
dcibot commented Apr 7, 2025

Copy link

@nsilla nsilla force-pushed the concurrent_release_mirror branch from 33a30f4 to eb3c103 Compare April 7, 2025 13:35
Copy link

@dcibot
Copy link
Collaborator
dcibot commented Apr 7, 2025

@nsilla nsilla requested a review from tonyskapunk April 8, 2025 08:57
Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions github-actions bot added the Stale label May 19, 2025
Copy link
Contributor
coderabbitai bot commented May 19, 2025

Walkthrough

This update refactors several Ansible tasks in the mirror_ocp_release role. It introduces a temporary workspace for artifact extraction, unifies and renames fact variables, updates file and image fetching logic, and improves command formatting and result registration. The changes focus on consistency, clarity, and atomic file operations without altering public interfaces.

Changes

File(s) Change Summary
roles/mirror_ocp_release/tasks/artifacts.yml Refactored artifact extraction to use a temporary directory and consolidated copying, permission, and SELinux operations into a single atomic shell command with file locking. Cleanup now removes the temporary directory instead of a lock file.
roles/mirror_ocp_release/tasks/facts.yml Switched from cat to slurp for reading rhcos.json, decoding and parsing its content. Renamed main fact variable from ocp_release_data to mor_ocp_release_data, updated all references, and improved JSON querying and fact setting for clarity and maintainability.
roles/mirror_ocp_release/tasks/fetch.yml Removed pre-fetch file existence check. Fetch task always registers result as _mor_downloaded. Updated retry condition to use the new variable. SELinux restorecon result now registered as _mor_restorecon with explicit changed_when.
roles/mirror_ocp_release/tasks/files.yml Renamed the result variable for the get_url task from downloaded to _mor_downloaded and updated the corresponding retry condition.
roles/mirror_ocp_release/tasks/images.yml Updated references for RHCOS image data from ocp_release_data to mor_ocp_release_data in the image fetching loop.
roles/mirror_ocp_release/tasks/main.yml Renamed the result variable for the authentication file check from mor_auths_file_check to _mor_auths_file_check and updated its reference in the assertion.
roles/mirror_ocp_release/tasks/registry.yml Unified command-line option formatting, corrected image source variable to mor_ocp_release_data['container_image'], added changed_when for skopeo inspect, and refactored mirror instructions flag handling for clarity and consistency.

Sequence Diagram(s)

sequenceDiagram
    participant Ansible
    participant TempDir
    participant CacheDir

    Ansible->>TempDir: Extract OCP installer and metadata
    Ansible->>TempDir: Conditionally extract rhcos.json
    Ansible->>TempDir: Fetch rhcos.json for <4.8 (if needed)
    Ansible->>TempDir: Check SELinux status
    Ansible->>CacheDir: Atomically copy artifacts with rsync, apply SELinux context & permissions (with lock)
    Ansible->>TempDir: Remove temporary directory
Loading

Poem

Hop, hop, in the playbook's warren,
Tasks renamed and logic sharpened,
Temp dirs bloom, then fade away,
Facts unified in a tidy array.
With every fetch and shell command,
This rabbit's code is sleek and grand!
🐇✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (7)
roles/mirror_ocp_release/tasks/fetch.yml (1)

30-31: Review SELinux context task changed_when logic.
Using changed_when: _mor_restorecon.rc == 0 will mark the task as changed whenever restorecon succeeds, even if no context modifications occurred. Consider adding idempotency checks (e.g., changed_when: _mor_restorecon.stdout) or using the ansible.posix.selinux module for more accurate change reporting.

roles/mirror_ocp_release/tasks/registry.yml (2)

18-26: Avoid register variable collisions and improve readability.
The register: _mor_result is reused here and again in the manifest generation task, which can lead to confusion and unintended overrides. Consider using distinct register variables (e.g., _mor_mirror_result for this task) and splitting inline conditional flags for clarity:

-    --from={{ mor_ocp_release_data['container_image'] | quote }}
+    --from={{ mor_ocp_release_data['container_image'] | quote }}
@@
-    --to={{ mor_registry_url }}/{{ mor_registry_path }}{%- if mor_allow_insecure_registry | bool %}
-    --insecure{%- endif %}
+    --to={{ mor_registry_url }}/{{ mor_registry_path }}
+    {% if mor_allow_insecure_registry | bool %}--insecure{% endif %}
@@
-  register: _mor_result
+  register: _mor_mirror_result
-  until: _mor_result.rc == 0
+  until: _mor_mirror_result.rc == 0
-  changed_when: _mor_result.rc == 0
+  changed_when: _mor_mirror_result.rc == 0

40-44: Correct whitespace in mirror_instructions and separate flag templating.
The variable mirror_instructions includes an unintended leading space, which may introduce extra whitespace in the command. Refactor as:

- mirror_instructions: "--print-mirror-instructions= {{ mor_is_type | lower }}"
+ mirror_instructions: "--print-mirror-instructions={{ mor_is_type | lower }}"

Then use it cleanly in the command:

{{ mor_version is version("4.14", "<") | ternary("--dry-run", mirror_instructions) }}

This removes extraneous spaces and keeps the flag templating clear.

roles/mirror_ocp_release/tasks/facts.yml (2)

67-75: Maintain backward compatibility for <4.8 releases
The < 4.8 loop mirrors the ≥4.8 logic with appropriate URI construction and fallback defaults, preserving legacy support.

Consider renaming add_item to something like image_fact for clearer intent within the loop.


112-116: Atomic OS image URL overrides
Building bootstraposimage, clusterosimage, and metalosimage from rhcos_images guarantees correct artifact references. Verify that mor_webserver_url consistently excludes a trailing slash to avoid double-slashes in generated URLs.

Optionally, apply | urlencode on the sha256 query parameters if downstream URL parsers require strict encoding.

roles/mirror_ocp_release/tasks/artifacts.yml (2)

21-32: Use dedicated temp dir for installer extraction
Extracting the OCP installer into _mor_tmp.path with retries and changed_when makes this step robust.

Consider distinct register names (e.g., _mor_installer_extract_res vs _mor_metadata_extract_res) to avoid overwriting logs and aid debugging.


81-93: Atomic copy with locking and permissions
The flock + rsync wrapper secures the cache directory against concurrent writes and applies SELinux and executable-bit adjustments in one atomic operation.

Since this is local, consider dropping -z from rsync -avz to avoid unnecessary compression overhead.

Review the indentation inside the single-quoted flock -c block to ensure no unintended whitespace alters command parsing.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 6163a2b and eb3c103.

📒 Files selected for processing (7)
  • roles/mirror_ocp_release/tasks/artifacts.yml (3 hunks)
  • roles/mirror_ocp_release/tasks/facts.yml (3 hunks)
  • roles/mirror_ocp_release/tasks/fetch.yml (2 hunks)
  • roles/mirror_ocp_release/tasks/files.yml (1 hunks)
  • roles/mirror_ocp_release/tasks/images.yml (1 hunks)
  • roles/mirror_ocp_release/tasks/main.yml (1 hunks)
  • roles/mirror_ocp_release/tasks/registry.yml (2 hunks)
🔇 Additional comments (9)
roles/mirror_ocp_release/tasks/files.yml (1)

16-17: Consistent internal variable naming for download results.
Renamed the registered variable to _mor_downloaded and updated the retry condition accordingly to follow the underscore-prefixed convention for internal task results.

roles/mirror_ocp_release/tasks/main.yml (1)

15-23: Consistent internal variable naming for authentication file check.
Renamed the registered variable to _mor_auths_file_check and updated its reference in the assertion to maintain consistency with underscore-prefixed internal variables across tasks.

roles/mirror_ocp_release/tasks/images.yml (1)

5-6:

✅ Verification successful

Update RHCOS image data variable references.
The task now correctly references mor_ocp_release_data['rhcos_images'] instead of the old ocp_release_data. Ensure mor_ocp_release_data is defined in facts.yml to avoid undefined variable errors.
Run the following to confirm no leftover ocp_release_data references:


🏁 Script executed:

#!/bin/bash
# Confirm renaming of release data variable
rg -n "ocp_release_data" -C2 roles/mirror_ocp_release/tasks

Length of output: 3787


Review complete: mor_ocp_release_data is correctly defined and no ocp_release_data remains
Confirmed that mor_ocp_release_data is set in roles/mirror_ocp_release/tasks/facts.yml (lines 26–30 & 72–75) and a ripgrep search shows no leftover ocp_release_data references in roles/mirror_ocp_release/tasks.

roles/mirror_ocp_release/tasks/registry.yml (1)

6-11: Add idempotent change detection for image availability check.
The changed_when: _mor_release_image.rc == 0 marks the inspect as changed on success, while failed_when: false prevents failures if the image is already present. This correctly avoids playbook failures on pullable images.

roles/mirror_ocp_release/tasks/facts.yml (2)

16-22: Leverage slurp for robust JSON retrieval
Switching from cat/command to ansible.builtin.slurp ensures idempotent, platform-agnostic reads of rhcos.json. The no_log: true flag appropriately hides sensitive content.


26-32: Unify JSON parsing and fact naming
The introduction of rhcos_json (decoding _mor_rhcos.content) and consolidation under mor_ocp_release_data aligns with the role’s conventions. The combine with default({}) correctly accumulates per-item entries.

Please confirm that all downstream tasks (images.yml, registry.yml, etc.) now reference mor_ocp_release_data instead of the old ocp_release_data.

roles/mirror_ocp_release/tasks/artifacts.yml (3)

10-15: Create isolated workspace per run
Adding a tempfile directory scoped to each invocation is crucial for thread-safe extraction. The when clause correctly gates creation on cache misses or forced runs.


34-45: Extract metadata to the shared temp workspace
The metadata extraction aligns with the installer step, ensuring all artifacts land in the same temp folder before publishing.


95-98: Cleanup temporary workspace reliably
The always block ensures the temp directory is removed regardless of success or failure, preventing disk-space leaks.

Comment on lines +15 to 18
register: _mor_downloaded
until: _mor_downloaded is not failed
when:
- mor_force or not target.stat.exists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined target variable in fetch condition causing runtime errors.
The when clause references target.stat.exists, but the stat task and target registration were removed, leading to an undefined variable. You should reintroduce a stat task before this fetch or update the condition to reference an existing variable.
Example fix:

+  - name: "Check if target file exists"
+    ansible.builtin.stat:
+      path: "{{ mor_dir }}/{{ mor_uri | basename }}"
+    register: target
   - name: "Fetch file from URL"
     ansible.builtin.get_url:
       url: "{{ mor_uri }}"
       dest: "{{ mor_dir }}"
@@
-  when:
-    - mor_force or not target.stat.exists
+  when:
+    - mor_force or not target.stat.exists
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
register: _mor_downloaded
until: _mor_downloaded is not failed
when:
- mor_force or not target.stat.exists
- name: "Check if target file exists"
ansible.builtin.stat:
path: "{{ mor_dir }}/{{ mor_uri | basename }}"
register: target
- name: "Fetch file from URL"
ansible.builtin.get_url:
url: "{{ mor_uri }}"
dest: "{{ mor_dir }}"
register: _mor_downloaded
until: _mor_downloaded is not failed
when:
- mor_force or not target.stat.exists
🤖 Prompt for AI Agents
In roles/mirror_ocp_release/tasks/fetch.yml around lines 15 to 18, the when
condition references target.stat.exists, but the target variable is undefined
because the stat task and its registration were removed. To fix this, add a stat
task before this fetch task to check the existence of the target file or
directory and register it as target, or modify the when condition to use an
existing variable that indicates the target's presence. Ensure the variable used
in the when clause is properly defined to avoid runtime errors.

@github-actions github-actions bot removed the Stale label May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0