0Pricing
Ansible Academy · Lesson

The Recommended Directory Layout

Where playbooks, inventory and vars live.

The Recommended Directory Layout is a free Ansible Academy lesson on CoddyKit — lesson 1 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 Layout Matters

As projects grow, scattered files become chaos. A standard directory layout tells your team exactly where everything lives. 📁

The site.yml Entry Point

By convention, site.yml is the top-level playbook that ties your whole infrastructure together and includes the rest.

# site.yml
- import_playbook: webservers.yml
- import_playbook: dbservers.yml

Inventory at the Root

Your inventory file (or directory) sits near the top, so the playbooks beside it always know which hosts they manage.

myproject/
  inventory
  site.yml

Per-Function Playbooks

Split big plays into focused files like webservers.yml and dbservers.yml, then stitch them together from site.yml.

The group_vars Directory

A group_vars directory holds variables that apply to whole host groups, loaded automatically by group name.

group_vars/
  webservers.yml
  dbservers.yml

The host_vars Directory

The host_vars directory does the same for single machines, with one file named after each individual host.

host_vars/
  web01.example.com.yml

The roles Directory

Reusable automation lives under a roles directory. Ansible looks here first when a play references a role by name.

roles/
  common/
  nginx/

Custom library and Plugins

A library folder holds custom modules, and module_utils or filter_plugins hold shared helper code Ansible auto-discovers.

Keep ansible.cfg Close

Place ansible.cfg at the project root. Ansible picks up the config from your current directory, keeping settings project-local.

# ansible.cfg
[defaults]
inventory = ./inventory
roles_path = ./roles

One Repo, Whole Picture

With this layout, one git clone gives a teammate the playbooks, inventory, variables and roles all in one consistent shape. 🎯

The Full Skeleton

Here is the recommended skeleton the official docs suggest. Memorize the shape, not every file.

myproject/
  ansible.cfg
  inventory
  site.yml
  group_vars/
  host_vars/
  roles/

Quick Check

Which file is the conventional top-level entry point for a whole project?

Recap

You learned the standard layout: site.yml plus inventory, group_vars, host_vars and roles in one repo. A predictable shape scales with your team. ✅

Frequently asked questions

Is the “The Recommended Directory Layout” lesson free?

Yes — the full text of “The Recommended Directory Layout” 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 “The Recommended Directory Layout”?

Where playbooks, inventory and vars live. 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 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The Recommended Directory Layout” 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. The Recommended Directory Layout
  2. group_vars & host_vars Directories
  3. Splitting Playbooks with import & include
  4. Naming, Comments & Style That Scale
← Back to Ansible Academy