From the course: Red Hat Certified Engineer (EX294) Cert Prep: 1 Foundations of Ansible

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Targeting hosts with patterns

Targeting hosts with patterns

From the course: Red Hat Certified Engineer (EX294) Cert Prep: 1 Foundations of Ansible

Start my 1-month free trial

Targeting hosts with patterns

- When running ad hoc commands or playbooks, you'll be targeting certain hosts to run them against. For this, you'll use patterns. An Ansible pattern can refer to a Single host, IP Address, and Inventory Group, a set of groups or all hosts in your inventory. Patterns can be very flexible. You can include and exclude subsets of hosts, use wildcards or even regular expressions. For ad hoc commands, the pattern might look like this. In this case, we're sending the reboot command to all hosts in the Ansible group web servers that we set up in our inventory. For our setup, this happens to be the rhhost TVM The same thing in a playbook looks like this, we put the pattern after the host keyword. common patterns are, all or asterisks for all hosts, the host name for one host, an Ansible groups such as web servers for all hosts in the Ansible group named web servers, host names separated by a colon for more than one…

Contents