I have problem with conditions in ansible
.
Here is my code sample:
// some code that generates result with lines
when: result.stdout_lines | length > 0
block:
- name: generates json
// some magic
register: jsonFile
- name: processing json
// some json parcing magic
when condition in json
The problem is: block
is using for all sub-tasks condition when: result.stdout_lines | length > 0
If sub-task has its own condition, when: result.stdout_lines | length > 0
is dropped.
It is mentioned in documentation for block
So when ansible
hits when: result.stdout_lines | length > 0
it is trying to do - name: processing json
.
- name: processing json
fails, because - name: generates json
wasn't executed.
But i don't want to execute this 2 tasks if result is empty.
What should i use instead of block
to "hide" sub-tasks from execution?
Ansible
version is 2.9