Grouping Hosts: web, db & app
Organize servers into logical groups.
Grouping Hosts: web, db & app 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.
Why Group Hosts
A group lets you act on many servers at once. Instead of naming each host, you target the role they share.
Name Groups by Role
Good group names describe a server's job: web, db, app. The name becomes how you target that tier in commands.
[web]
[db]
[app]Fill the web Group
List your front-end servers under the [web] header. Now any command aimed at web hits both of them.
[web]
web1.example.com
web2.example.comAdd a db Group
Group your database hosts under [db]. Keeping tiers separate means a risky db task never touches a web box.
[db]
db1.example.comTarget One Group
Pass a group name where you would name a host. Here Ansible pings only the db tier and ignores the rest.
ansible db -i inventory.ini -m pingA Host Can Join Many Groups
List the same host under two headers and it belongs to both groups. Handy for a box that runs app and web together.
[web]
node1.example.com
[app]
node1.example.comGrouping in YAML
In YAML, each group sits under children, with its own hosts block. Same idea, nested structure.
all:
children:
web:
hosts:
web1.example.com:List a Group's Members
Confirm who belongs where with --list-hosts. It prints exactly the servers a group pattern resolves to.
ansible app -i inventory.ini --list-hostsungrouped Catches Strays
Hosts you list with no group land in the built-in ungrouped group. A quick way to spot servers you forgot to sort.
ansible ungrouped -i inventory.ini --list-hostsGroups Map to Real Tiers
Your web, db, and app groups mirror a classic three-tier stack. Automation now reads like your architecture.
Keep Names Consistent
Pick a naming convention and stick to it. Consistent group names across projects make playbooks reusable and reviews painless.
Quick Check
You list one host under both the [web] and [app] headers. What happens?
Recap
Groups like web, db, and app let you target whole tiers by name. A host can join several groups at once. 🗂️
Frequently asked questions
Is the “Grouping Hosts: web, db & app” lesson free?
Yes — the full text of “Grouping Hosts: web, db & app” 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 “Grouping Hosts: web, db & app”?
Organize servers into logical groups. 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 “Grouping Hosts: web, db & app” 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
- INI vs YAML Inventory Files
- Grouping Hosts: web, db & app
- Nested Groups & the children Keyword
- Host & Group Variables in the Inventory