Conditionnal 'changed_when' based on output in a 'with_items' task
up vote
0
down vote
favorite
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)
loops ansible
add a comment |
up vote
0
down vote
favorite
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)
loops ansible
The following answer didn't help me as it process it in the next task which is too late to update the task status I assume.
– xenlo
Nov 19 at 12:03
Check this: stackoverflow.com/a/43487756/2795592
– Konstantin Suvorov
Nov 19 at 12:06
That's also done in 2 tasks. It will not help me to have the correct status of my initial task.
– xenlo
Nov 19 at 12:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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)
loops ansible
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)
loops ansible
loops ansible
edited Nov 19 at 12:50
asked Nov 19 at 11:59
xenlo
106
106
The following answer didn't help me as it process it in the next task which is too late to update the task status I assume.
– xenlo
Nov 19 at 12:03
Check this: stackoverflow.com/a/43487756/2795592
– Konstantin Suvorov
Nov 19 at 12:06
That's also done in 2 tasks. It will not help me to have the correct status of my initial task.
– xenlo
Nov 19 at 12:47
add a comment |
The following answer didn't help me as it process it in the next task which is too late to update the task status I assume.
– xenlo
Nov 19 at 12:03
Check this: stackoverflow.com/a/43487756/2795592
– Konstantin Suvorov
Nov 19 at 12:06
That's also done in 2 tasks. It will not help me to have the correct status of my initial task.
– xenlo
Nov 19 at 12:47
The following answer didn't help me as it process it in the next task which is too late to update the task status I assume.
– xenlo
Nov 19 at 12:03
The following answer didn't help me as it process it in the next task which is too late to update the task status I assume.
– xenlo
Nov 19 at 12:03
Check this: stackoverflow.com/a/43487756/2795592
– Konstantin Suvorov
Nov 19 at 12:06
Check this: stackoverflow.com/a/43487756/2795592
– Konstantin Suvorov
Nov 19 at 12:06
That's also done in 2 tasks. It will not help me to have the correct status of my initial task.
– xenlo
Nov 19 at 12:47
That's also done in 2 tasks. It will not help me to have the correct status of my initial task.
– xenlo
Nov 19 at 12:47
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374175%2fconditionnal-changed-when-based-on-output-in-a-with-items-task%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The following answer didn't help me as it process it in the next task which is too late to update the task status I assume.
– xenlo
Nov 19 at 12:03
Check this: stackoverflow.com/a/43487756/2795592
– Konstantin Suvorov
Nov 19 at 12:06
That's also done in 2 tasks. It will not help me to have the correct status of my initial task.
– xenlo
Nov 19 at 12:47