Patterns: Targeting all, web & host1
Select exactly which hosts a command hits.
Patterns: Targeting all, web & host1 is a free DevOps Bootcamp lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, and your progress syncs across the web and the CoddyKit app. The DevOps Bootcamp course includes 4 lessons in total.
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 pingTarget 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 pingTarget a Single Host
Pass one hostname, such as host1, to run the command on just that machine and nothing else.
ansible host1 -m pingCombine 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 pingExclude with :!
The :! operator subtracts hosts. all:!db means every host except those in the db group.
ansible all:!db -m pingIntersect with :&
The :& operator keeps only hosts in both sets. web:&staging matches web servers that are also staging.
ansible web:&staging -m pingWildcards 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 pingLimit 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 host1Preview with --list-hosts
Add --list-hosts to see exactly which machines a pattern resolves to, without running anything on them.
ansible web:db --list-hostsPatterns 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 pingQuick 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. 🎯
Learn DevOps Bootcamp with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 142
- Lessons
- 568
Frequently Asked Questions
Is the “Patterns: Targeting all, web & host1” lesson free?
Yes — any 3 lessons of the DevOps Bootcamp learning path, including “Patterns: Targeting all, web & host1”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The DevOps Bootcamp course includes 4 lessons in total.
What will I learn in “Patterns: Targeting all, web & host1”?
Select exactly which hosts a command hits. You practise DevOps Bootcamp 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 DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.
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 DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp 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
- Anatomy of the ansible Command
- Patterns: Targeting all, web & host1
- Run Shell Commands with command & shell
- Privilege Escalation with become