0Pricing
Ansible Academy · Lesson

YAML Syntax You Need for Ansible

Indentation, lists and key-value mappings.

YAML Syntax You Need for Ansible 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.

Playbooks Are Just YAML

Every Ansible playbook is written in YAML, a plain-text format built to be easy for humans to read and write.

Documents Start With ---

A YAML file usually opens with three dashes. This --- marks the start of the document, and Ansible expects to see it.

---
# my first playbook below this line

Indentation Is Everything

YAML uses indentation to show structure. Spaces mean nesting, so what is indented under a line belongs to it.

Spaces, Never Tabs

Always indent with spaces in YAML. A literal tab character is invalid and Ansible will refuse to parse the file.

Key-Value Mappings

The core of YAML is the mapping: a key, a colon, a space, then the value. This is how you set every option.

name: install nginx
state: present

The Colon Needs a Space

That single space after the colon is required. Writing name:value with no space confuses the parser, so keep the gap.

Lists Use Dashes

A list is a set of items, each on its own line starting with a dash and a space. Playbooks are really just lists of plays.

packages:
  - nginx
  - git
  - curl

Lists of Mappings

Ansible tasks combine both ideas: a list of mappings. Each dash begins a task, and indented keys describe it.

tasks:
  - name: say hello
    debug:
      msg: hi

Strings Often Need No Quotes

Plain text values usually need no quotes. Add quotes only when a value has colons, braces, or starts with a special character.

msg: "value: with a colon needs quotes"

Booleans and Numbers

YAML reads true, false, and bare digits as booleans and numbers, not text. So yes and 22 are typed values, not strings.

enabled: true
port: 22

Comments Start With #

Anything after a # on a line is a comment. Ansible ignores it, so use comments to explain what each task is doing.

# this task installs the web server
- name: install nginx

Quick Check

You need to indent a nested line in your playbook. What do you use?

You Know Enough YAML

That is the whole toolkit: mappings, lists, and indentation with spaces. Master these few rules and every playbook reads clearly. 🎉

Frequently asked questions

Is the “YAML Syntax You Need for Ansible” lesson free?

Yes — the full text of “YAML Syntax You Need for Ansible” 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 “YAML Syntax You Need for Ansible”?

Indentation, lists and key-value mappings. 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 “YAML Syntax You Need for Ansible” 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. YAML Syntax You Need for Ansible
  2. From Ad-Hoc to a Repeatable Playbook
  3. Run It with ansible-playbook
  4. Install Nginx in Five Lines
← Back to Ansible Academy