Reputation: 170390
Imagine this Ansible code that is supposed to set the task as failed only when the command returns a value different than 0 or 1.
- shell: some-command
register: result
failed_when: result.rc not in [0, 1] or 'err' in result.stdout_lines
How it would look the variant that does use a with_items loop? As you probably know for these result structure would contain a results
dictionary which stores the results of each item.
Sadly for us, we want to decide the failed status by looking at all.
- shell: "{{ item }}"
register: result
failed_when: ????
with_items:
- ls
- df
Upvotes: 0
Views: 1206
Reputation: 68459
This is a non-issue. Use the same condition as in your first example:
- shell: "{{ item }}"
register: result
failed_when: result.rc not in [0, 1] or 'err' in result.stdout_lines
with_items:
- ls
- df
As you probably know for these result structure would contain a
results
dictionary which stores the results of each item.
Except that this structure is created after the execution and is accessible from subsequent tasks, not from inside the loop.
Upvotes: 2