harbor run -t scale-ai/hil-bench-swe_48-ask_humanharbor download scale-ai/hil-bench-swe_48-ask_humanWhen a task uses both loops and delegate_to in Ansible, their values are calculated twice. This redundant work during execution affects how delegation and loop evaluation interact and can lead to inconsistent results.
The fix also needs to keep legacy delegation variable resolution available during the transition period while clearly signaling that callers must migrate to the new execution path.
Tasks that include both loop and delegate_to trigger duplicate calculations of these values. The loop items and the delegation target may be processed multiple times within a single task execution.
Delegation resolution can also vary depending on where the delegated target comes from, which makes behavior harder to reason about when templated targets are used.
Loop values and delegate_to should be calculated only once per task execution. Delegation should be resolved at a single deterministic point in task execution, and loop items should be evaluated a single time.
Delegated target resolution should follow one consistent strategy across direct hostnames and templated values.
Legacy delegation resolution entry points should emit a deprecation warning that communicates the planned removal release according to project policy.
loop with a delegate_to directive target.delegate_to value once per task execution at a single pre-loop execution stage, ensuring that both loop items and delegation are not redundantly recalculated.Name: get_delegated_vars_and_hostname Path: lib/ansible/vars/manager.py
Input: - templar - task - variables
Output: - (delegated_vars: dict, delegated_host_name: str | None) Description: New public method in VariableManager. Returns the final templated hostname for delegate_to and a dictionary with the delegated variables associated to that host. Prevents double evaluation of loops and centralizes delegation logic.
Name: get_play
Path: lib/ansible/playbook/task.py
Input: self
Output: - Play object associated with the task
Description: New public method in Task. Traverses the parent hierarchy until it finds a Block and returns the containing Play, required for delegation calculations in VariableManager.