Question:
How do I use the when statement based on the standard output of register: result? If standard output exists I want somecommand to run if no standard output exists I want someothercommand to run.
1 2 3 4 5 6 7 8 9 10 |
- hosts: myhosts tasks: - name: echo hello command: echo hello register: result - command: somecommand {{ result.stdout }} when: result|success - command: someothercommand when: result|failed |
Answer:
Try checking to see it if equals a blank string or not?
1 2 3 4 5 6 7 8 9 10 |
- hosts: myhosts tasks: - name: echo hello command: echo hello register: result - command: somecommand {{ result.stdout }} when: result.stdout != "" - command: someothercommand when: result.stdout == "" |