My goal is to perform tasks only one host based on the output. Searched for --limit module to use in playbooks, but it is not present.
A shell script is executed on 3 nodes, which returns a boolean.
ok: [localMulti1] => {
"variable": {
...
"stdout": "true",
...
}
}
ok: [localMulti2] => {
"variable": {
...
"stdout": "false",
...
}
}
ok: [localMulti3] => {
"variable": {
...
"stdout": "false",
...
}
}
How can I perform tasks on only on localMulti2? But not statically include the host (inventory_hostname == '...')
Failing with:
- shell: echo
when: variable.stdout == "false" and ...
when: variable.stdout == "false"Register: myVar
Task: a task
Shell: echo
When: myVar is defined
Delegate_to: "{{ first-host-where_myVar is defined }}"Let met clarify. This is my output.
ok: [localMulti1] => {
"variable": {
...
"stdout": "true",
...
}
}
ok: [localMulti2] => {
"variable": {
...
"stdout": "false",
...
}
}
ok: [localMulti3] => {
"variable": {
...
"stdout": "false",
...
}
}
How can I configure ansible to perform only a task on the second node, where the stdout is false. Not the third node
Run_once will never work, because it will always run it on the second host.
TASK [command] *****************************************************************
Saturday 17 December 2016 14:08:12 +0100 (0:00:00.101) 0:00:01.122 *****
skipping: [localMulti1]
skipping: [localMulti3]
changed: [localMulti2]
PLAY RECAP *********************************************************************
localMulti1 : ok=3 changed=0 unreachable=0 failed=0
localMulti2 : ok=3 changed=1 unreachable=0 failed=0
localMulti3 : ok=2 changed=0 unreachable=0 failed=0