How do you target hosts with a regex pattern?

IntermediateConceptInventory
Answer

Start the pattern with ~. It matches against host names or group names using Python regex.

ansible '~(web|app)[0-9]+\.prod' -m ping
ansible-playbook site.yml --limit '~db-eu-.*'

Remember to quote the pattern so the shell does not expand it. Combine with other operators, for example ~web[0-9]+:&prod.

All Ansible questions Roadmap: Ansible

More on Inventory