如果变量与给定的正则表达式不匹配,则查找将使playbook失败的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])?)*
答案 0 :(得分:2)
您可能想要使用assert module:
- assert:
that:
- inventory_hostname | match('your regex')