0Pricing
Ansible Academy · Lesson

Scaffold a Role with ansible-galaxy init

Generate the standard role skeleton.

Scaffold a Role with ansible-galaxy init is a free Ansible Academy lesson on CoddyKit — lesson 3 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.

Do Not Build It By Hand

You could create every role folder manually, but Ansible gives you a command that scaffolds the whole structure in one step.

ansible-galaxy init

The ansible-galaxy init command generates a complete, ready-to-fill role skeleton with all the standard directories.

ansible-galaxy init nginx

Name the Role Clearly

The argument you pass becomes the role's folder name. Pick something descriptive like webserver or postgres so its purpose is obvious.

What Gets Created

The command builds tasks, handlers, templates, files, vars, defaults, meta, and tests folders, each with a starter main.yml ready to edit.

nginx/
  tasks/main.yml
  handlers/main.yml
  defaults/main.yml
  meta/main.yml

Run It Inside roles/

Run the command from your project's roles directory so the new role lands where playbooks expect to find it.

cd roles
ansible-galaxy init webserver

Starter Files Are Empty Stubs

Each generated main.yml arrives almost empty, with just a comment header. You fill in the real tasks and variables yourself.

meta Comes Pre-Filled

The meta/main.yml stub includes placeholders for author, license, and platforms. Update these before sharing the role.

A README Is Included

The scaffold also drops a README.md template, nudging you to document what the role does and which variables it accepts.

Use a Custom Path

Pass --init-path to create the role somewhere other than the current folder, handy when your roles live in a dedicated directory.

ansible-galaxy init nginx --init-path roles/

Consistency Across the Team

Because everyone scaffolds with the same command, every role in your project shares an identical, predictable layout.

Then Start Writing Tasks

With the skeleton ready, your next move is editing tasks/main.yml to define what the role actually installs or configures.

Quick Check

Recall the command that scaffolds a fresh role.

Recap

Run ansible-galaxy init to scaffold a complete role skeleton instantly, then fill the stub files with your real tasks and variables. 🛠️

Frequently asked questions

Is the “Scaffold a Role with ansible-galaxy init” lesson free?

Yes — the full text of “Scaffold a Role with ansible-galaxy init” 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 “Scaffold a Role with ansible-galaxy init”?

Generate the standard role skeleton. 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 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Scaffold a Role with ansible-galaxy init” 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. Why Roles: From Monolith to Modules
  2. The Role Directory Anatomy
  3. Scaffold a Role with ansible-galaxy init
  4. Apply Roles & Pass Role Variables
← Back to Ansible Academy