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.
- hosts: myhosts tasks: - name: echo hello command: echo hello register: result - command: somecommand {{ result.stdout }} when: result|success - command: someothercommand when: result|failed
Ansible modules normally return a data structure that can be registered into a variable, or seen directly when output by the ansible program. Each module can optionally document its own unique return values (visible through ansible-doc and on the main docsite).
Create the playbook to execute the “df” command to check the /boot usage. Use “register” to store the output to a variable. 2. Run the playbook to see the result.
Try checking to see it if equals a blank string or not?
- hosts: myhosts tasks: - name: echo hello command: echo hello register: result - command: somecommand {{ result.stdout }} when: result.stdout != "" - command: someothercommand when: result.stdout == ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With