Closed lukasmrtvy closed 2 years ago
The basic ideas are:
see an example from: https://github.com/upcmd/up/blob/master/up.yml
Problem is that curl in "enquire the latest release" task might fail due to:
Look at Ansible uri module for example: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html You can define response codes that signifies success of the request:
status_code:
- 200
- 201
Its much more generic way how to check if request was successful, than parsing output body.
You will have to handle it yourself.
I have come up with an example: https://github.com/upcmd/up/blob/master/tests/functests/c0209.yml
result example:
~~SubStep1: [return: ]
=Task2: [task ==> handle_exit_code: ]
--Step1: [: prototyping the case to randomly get a http response either 200 or 201 ]
cmd( 1):
-
200
-
.. ok
. ok
--Step2:
dvar> success:
"true"
-
true
~~SubStep1: [return: ]
=Task2: [task ==> handle_exit_code: ]
--Step1: [: prototyping the case to randomly get a http response either 200 or 201 ]
cmd( 1):
-
302
-
.. ok
. ok
--Step2:
dvar> success:
"false"
-
false
~~SubStep1: [return: ]
=Task2: [task ==> handle_exit_code: ]
--Step1: [: prototyping the case to randomly get a http response either 200 or 201 ]
cmd( 1):
-
302
-
.. ok
. ok
--Step2:
dvar> success:
"false"
-
false
~~SubStep1: [return: ]
=Task2: [task ==> handle_exit_code: ]
--Step1: [: prototyping the case to randomly get a http response either 200 or 201 ]
cmd( 1):
-
500
-
.. ok
. ok
--Step2:
dvar> success:
"false"
-
false
~~SubStep1: [return: ]
=Task2: [task ==> handle_exit_code: ]
--Step1: [: prototyping the case to randomly get a http response either 200 or 201 ]
cmd( 1):
-
200
-
.. ok
. ok
--Step2:
dvar> success:
"true"
-
true
~~SubStep1: [return: ]
=Task2: [task ==> handle_exit_code: ]
--Step1: [: prototyping the case to randomly get a http response either 200 or 201 ]
cmd( 1):
-
301
-
.. ok
. ok
--Step2:
dvar> success:
"false"
-
false
~~SubStep1: [return: ]
-Step3: [: show if the above http request is successful ]
~SubStep1: [print: ]
?success: false
Any idea, how to loop over curl result ( json ) and at the same check if curl reponse code = 200 or 201 ; else fail ?
Usually this is possible:
But I am not sure, if is possible to register stderr: