Looking for an Ansible task that will fail the playbook if a variable does not match a given regex. Something like:
# 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])?)*
asked Feb 12, 2018 at 18:52
1 Answer 1
You probably want to use the assert module:
- assert:
that:
- inventory_hostname is match('your regex')
See also Playbook Tests and Filters
Dale C. Anderson
2,4801 gold badge28 silver badges26 bronze badges
answered Feb 12, 2018 at 19:01
Sign up to request clarification or add additional context in comments.