I'm trying to clean up some of our expected errors and make them more understandable to the operators running the playbooks. The code below works just fine, but I would like to assign a custom message to each of the failure conditions. For example, if var1 does not equal 4 then I'd like to present a message that says "There were not 4 entries in the lldp neighbor for neighbor x"
- name: Verify Number of bundles for output of show lldp neigh
set_fact:
var1: "{{lldp_spine3.data | regex_findall('ae1')}}"
var2: "{{lldp_spine3.data | regex_findall('ae2')}}"
failed_when: (var1 != 4) or (var2 | length != 4)
I know I can split those up and follow the logic below but I'd like to know if I can accomplish this in a single play.
- fail:
msg: "There were not 4 entries in the lldp neighbor for neighbor x"
when: var1|length != 4
- fail:
msg: "There were not 4 entries in the lldp neighbor for neighbor y"
when: var2|length != 4