0Pricing
Ansible Academy · Lesson

Patterns: Targeting all, web & host1

Select exactly which hosts a command hits.

Patterns: Targeting all, web & host1 is a free Ansible Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Ansible Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Patterns Pick the Targets

A host pattern is the first argument that decides exactly which inventory hosts an ad-hoc command will run against. 🎯

all Hits Everything

The special pattern all matches every host in your inventory. Use it for fleet-wide checks like a quick ping.

ansible all -m ping

Target a Group by Name

Use a group name like web to hit only the hosts in that group, leaving every other server untouched.

ansible web -m ping

Target a Single Host

Pass one hostname, such as host1, to run the command on just that machine and nothing else.

ansible host1 -m ping

Combine with a Colon

Join targets with a colon to form a union. web:db reaches every host in either group at once.

ansible web:db -m ping

Exclude with :!

The :! operator subtracts hosts. all:!db means every host except those in the db group.

ansible all:!db -m ping

Intersect with :&

The :& operator keeps only hosts in both sets. web:&staging matches web servers that are also staging.

ansible web:&staging -m ping

Wildcards Match Names

A wildcard like web*.example.com matches every host whose name fits the pattern. Quote it so your shell leaves it alone.

ansible "web*" -m ping

Limit a Run with --limit

The --limit flag narrows any pattern further at runtime, handy for testing on one host before going wide.

ansible web -m ping --limit host1

Preview with --list-hosts

Add --list-hosts to see exactly which machines a pattern resolves to, without running anything on them.

ansible web:db --list-hosts

Patterns Combine Freely

You can chain operators in one pattern: web:db:!host1 means all web and db hosts, but skip host1.

ansible web:db:!host1 -m ping

Quick Check

How do you exclude a group from a host pattern?

Recap

You can now aim precisely: all for everything, group or host names to narrow, and :, :& and :! to combine sets. 🎯

Frequently asked questions

Is the “Patterns: Targeting all, web & host1” lesson free?

Yes — the full text of “Patterns: Targeting all, web & host1” is free to read here on the web, and the Ansible Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Ansible Academy course, upgrade to CoddyKit PRO.

What will I learn in “Patterns: Targeting all, web & host1”?

Select exactly which hosts a command hits. You practise Ansible Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Ansible Academy?

No prior experience is required. Ansible Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Patterns: Targeting all, web & host1” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Ansible Academy lesson?

Yes. Every Ansible Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Anatomy of the ansible Command
  2. Patterns: Targeting all, web & host1
  3. Run Shell Commands with command & shell
  4. Privilege Escalation with become
← Back to Ansible Academy