Docs / Automation & IaC / Ansible Roles and Galaxy Best Practices

Ansible Roles and Galaxy Best Practices

By Admin · Mar 1, 2026 · Updated Apr 24, 2026 · 24 views · 1 min read

Ansible Roles and Galaxy Best Practices

As your Breeze fleet grows, playbooks become unwieldy. Ansible roles let you organize tasks, handlers, templates, and variables into reusable components. Galaxy provides a community repository of pre-built roles.

Creating a Role

ansible-galaxy init roles/webserver

This generates the standard role directory structure:

roles/webserver/
  tasks/main.yml
  handlers/main.yml
  templates/
  files/
  vars/main.yml
  defaults/main.yml
  meta/main.yml

Using Roles in Playbooks

---
- hosts: breezes
  become: true
  roles:
    - common
    - webserver
    - { role: firewall, firewall_ports: [80, 443] }

Installing from Galaxy

Use a requirements.yml file to pin role versions:

# requirements.yml
- name: geerlingguy.docker
  version: "6.1.0"
- name: geerlingguy.certbot
  version: "5.0.0"
ansible-galaxy install -r requirements.yml

Best Practices

  • Keep roles focused — one role per service or concern
  • Use defaults/main.yml for overridable variables and vars/main.yml for internal constants
  • Always pin Galaxy role versions in requirements.yml
  • Add a meta/main.yml with dependencies so roles auto-resolve
  • Test roles with ansible-playbook --check --diff before deploying to Breezes

Was this article helpful?