I have a simple shell task which is feed with_items
. I want to have the 'changed' status only when the run actually did something. So for that I have to parse the output and look for a «Done».
The issue is using a register
at the same time that the with_items
generates a list of results. And I don't find a way to access the stdout
of the current loop iteration.
---
- name: Test to set changed status only on when output match with 'Done'
hosts: my-host-01
gather_facts: no
tasks:
- name: Task doing stuff
shell: |
echo {{ item }}
register: do_stuff
with_items:
- "Doing... Done!"
- "Nothing to do"
#changed_when: do_stuff.results[{{ item.id }}].stdout.find('Done')
- name: Print 'do_stuff' var to debug
debug:
var: do_stuff
- name: Try to access to the desired stdout
debug:
var: do_stuff.results[0].stdout
The expected result that I want would be:
TASK [Task doing stuff]
*************************************************************************
changed: [cnode02] => (item=Doing... Done!)
Ok: [cnode02] => (item=Nothing to do)