How to Create Ansible Playbooks for Common Tasks
Ansible playbooks are YAML files that describe automation tasks to run on your Breezes. They transform repetitive system administration into reusable, version-controlled code.
Playbook Structure
Every playbook follows a consistent structure:
---
- name: Deploy web application
hosts: webservers
become: true
vars:
app_dir: /var/www/myapp
tasks:
- name: Install Nginx
apt:
name: nginx
state: present
- name: Copy Nginx config
template:
src: templates/nginx.conf.j2
dest: /etc/nginx/sites-available/default
notify: reload nginx
- name: Ensure app directory exists
file:
path: "{{ app_dir }}"
state: directory
owner: www-data
mode: '0755'
handlers:
- name: reload nginx
service:
name: nginx
state: reloaded
Common Modules
apt/yum— package managementservice— start, stop, restart servicestemplate— deploy Jinja2 configuration templatescopy— copy static files to remote hostsfile— manage file and directory permissionsuser— create and manage user accounts
Inventory File
Define your Breezes in inventory.ini:
[webservers]
breeze-web-01 ansible_host=192.168.1.10
breeze-web-02 ansible_host=192.168.1.11
[databases]
breeze-db-01 ansible_host=192.168.1.20
Use ansible-playbook -i inventory.ini playbook.yml --check to preview changes before applying them to production Breezes.