Question:
How can I test that stderr is non empty::
1 2 3 4 5 6 7 8 9 10 |
- name: Check script shell: . {{ venv_name }}/bin/activate && myscritp.py args: chdir: "{{ home }}" sudo_user: "{{ user }}" register: test_myscript - debug: msg='myscritp is Ok' when: not test_myscript.stderr |
So if there is no error I could read::
1 2 3 4 5 |
TASK: [deploy | debug msg='critp is Ok] ******* ok: [vagrant] => { "msg": "myscritp is Ok" } |
In case the stderr is not empty a FATAl
error occurs.
Answer:
You can check for empty string (when stderr is empty)
1 2 3 4 5 6 7 8 9 10 |
- name: Check script shell: . {{ venv_name }}/bin/activate && myscritp.py args: chdir: "{{ home }}" sudo_user: "{{ user }}" register: test_myscript - debug: msg='myscritp is Ok' when: test_myscript.stderr == "" |
If you want to check for fail:
1 2 3 |
- debug: msg='myscritp has error: {{test_myscript.stderr}}' when: test_myscript.stderr != "" |