postgresql_cluster
postgresql_cluster copied to clipboard
[Bug] pgbackrest role "The conditional check 'item.option == 'log-path'' failed." error
Bug description
Hi, I've encountered with this error:
The conditional check 'item.option == 'log-path'' failed. The error was: error while evaluating conditional (item.option == 'log-path'): 'item' is undefined
The error appears to be in '/home/runner/.ansible/collections/ansible_collections/vitabaks/autobase/roles/pgbackrest/tasks/main.yml': line 89, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- block:
- name: Ensure log directory exists
^ here
And here is the explanation:
The error 'item' is undefined occurs because Ansible cannot access the item variable when the when: condition is evaluated. This happens due to incorrect placement of the loop directive relative to the block.
Variable Scope Issue:
In Ansible, the item variable is only created within the context of a task that has a loop
When you place loop at the same level as block, the when: condition is evaluated before item exists
Structural Problem:
- block: # Problem: loop is inside the task but when is evaluated earlier
- name: Task
module: ...
loop: "{{ list }}" # Creates item
when: item.param # Tries to use item before it exists
Expected behavior
Running collection doesn't failing
Steps to reproduce
...
Installation method
Command line
System info
My ansible-core version 2.17.12 Ubuntu 22.04 github runner
Additional info
No response