How to evaluate a when condition for Ansible task
No need to use regex for pattern searching. You can use search like this:
when: name_prefix | search("stage-dbs")
It will definitely work.
Not sure filter search
exists today?
solution with https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#searching-strings-with-regular-expressions :
when: name_prefix | regex_search("^stage-dbs(.*)$")