0Pricing
Ansible Academy · Lesson

Group Tasks with block

Bundle tasks for shared behavior.

Tasks That Belong Together

Some tasks naturally form a unit. The block keyword groups several tasks so they can share settings and behavior. 📦

What a block Looks Like

A block is a list of tasks nested under one block key. They run top to bottom, just like normal tasks.

- name: Set up the app
  block:
    - name: Install package
      ansible.builtin.package:
        name: nginx
    - name: Start service
      ansible.builtin.service:
        name: nginx
        state: started

All lessons in this course

  1. Group Tasks with block
  2. Try / Catch with rescue & always
  3. Control Failure: failed_when & ignore_errors
  4. Custom Assertions with the fail Module
← Back to Ansible Academy