Reputation: 13
I am trying to error handle in ansible for http status code. My use case is to check for status code 400(fail code) and it needs to pass for 2 known error conditions. Like if content has particular search strings in 400 response. Sample task:
-name: create repo
uri:
url:
method: POST
body_format:json
.
.
status_code:
- 201
- 400
register: value
changed_when: value.status == 201
failed_when: value.status == 400 and
value.content|default() is not search ("found duplicate value")
Above is working but Expecting another search string with or condition to the same and 400 like.
-name: create repo
uri:
url:
method: POST
body_format:json
.
.
status_code:
- 201
- 400
register: value
changed_when: value.status == 201
failed_when: value.status == 400 and
( value.content|default() is not search ("found 1st duplicate value") or value.content|default() is not search ("found 2nd duplicate value") )
How to handle either condition 2 or's with the 'and'..
Upvotes: 0
Views: 1849
Reputation: 17007
i think you have parenthesis problem and you have to add simple quote: try:
failed_when: (value.status == 400) and
'(value.content|default() is not search ("found 1st duplicate value") or value.content|default() is not search ("found 2nd duplicate value"))'
Upvotes: 1