Ansible 如果变量与正则表达式不匹配,则失败
寻找一个Ansible任务,如果变量与给定的正则表达式不匹配,该任务将失败。比如:Ansible 如果变量与正则表达式不匹配,则失败,ansible,Ansible,寻找一个Ansible任务,如果变量与给定的正则表达式不匹配,该任务将失败。比如: # fail when hostname doesn't match a regex - fail: msg: "The inventory hostname must match regex" when: {{ inventory_hostname }} not matches [a-z](([-0-9a-z]+)?[0-9a-z])?(\.[a-z0-9](([-0-9a-z]+)?[0-9a-z
# fail when hostname doesn't match a regex
- fail:
msg: "The inventory hostname must match regex"
when: {{ inventory_hostname }} not matches [a-z](([-0-9a-z]+)?[0-9a-z])?(\.[a-z0-9](([-0-9a-z]+)?[0-9a-z])?)*
您可能希望使用以下选项: 另见和
- assert:
that:
- inventory_hostname | match('your regex')