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.
More on Inventory
What is an inventory and why does Ansible need one?BeginnerWhat are the INI and YAML inventory formats and how do they differ?BeginnerHow do you create groups of groups?BeginnerExplain host patterns: `:`, `:&`, `:!` and wildcards.IntermediateWhich connection variables can you set per host in inventory?BeginnerWhat are `group_vars` and `host_vars` directories?Intermediate