如果变量与正则表达式不匹配,则失败

时间:2018-02-12 18:52:38

标签: ansible

如果变量与给定的正则表达式不匹配,则查找将使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])?)*

1 个答案:

答案 0 :(得分:2)

您可能想要使用assert module

- assert:
    that:
    - inventory_hostname | match('your regex')

另请参阅Playbook TestsFilters