您可使用assert或fail/code/<>/>/>/>a/>。
Using assert
- name: check that variable is defined using assert
assert:
that: hostname|default( ) is in prod_mgmt_network
fail_msg: "hostname is not in prod_mgmt_network"
其结果如下:
TASK [check that variable is defined using assert] ********************************************************************************************************
fatal: [localhost]: FAILED! => {
"assertion": "hostname is defined",
"changed": false,
"evaluated_to": false,
"msg": "hostname is not in prod_mgmt_network"
}
Using fail
- name: check that variable is defined using fail
when: hostname|default( ) is not in prod_mgmt_network
fail:
msg: "hostname is not in prod_mgmt_network"
其结果如下:
TASK [check that variable is defined using fail] **********************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "hostname is not in prod_mgmt_network"}