Skip to main content

rawops.dev

Skip to tool content

Ansible Playbook Generator

Generate Ansible playbooks with tasks, handlers, variables, and roles. Includes inventory.ini and ansible.cfg generation. 100% client-side — nothing leaves your browser.

Play Settings

Connection

Variables

Tasks

#1Install Nginx
#2Deploy site configuration
#3Ensure Nginx is running and enabled
#4Allow HTTP through firewall

Handlers

Restart Nginx

Roles

Output Options

playbook.yml
# Generated by RawOps.dev — Ansible Playbook Generator
# Mode: web-server
---
- name: Configure Web Server
  hosts: webservers
  become: true

  vars:
    http_port: '80'
    server_name: example.com

  # Tasks
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present
        update_cache: 'yes'
      become: true
      notify: Restart Nginx
      tags: [install]

    - name: Deploy site configuration
      template:
        src: templates/nginx.conf.j2
        dest: /etc/nginx/sites-available/default
        mode: '0644'
      become: true
      notify: Restart Nginx
      tags: [configure]

    - name: Ensure Nginx is running and enabled
      service:
        name: nginx
        state: started
        enabled: 'yes'
      become: true
      tags: [service]

    - name: Allow HTTP through firewall
      ufw:
        rule: allow
        port: '{{ http_port }}'
        proto: tcp
      become: true
      tags: [firewall]

  # Handlers are triggered by 'notify' in tasks
  handlers:
    - name: Restart Nginx
      service:
        name: nginx
        state: restarted

Quick Recipes

Click a recipe to populate the form with a ready-to-use playbook configuration.

Ansible Playbook Guide

An Ansible playbook is a YAML file that describes a set of automation tasks to be executed on remote servers. Playbooks are the core of Ansible's configuration management — they define what should happen on which hosts, in what order.

Playbook vs Role vs Collection

ConceptPurposeScope
PlaybookOrchestration — defines what to run whereOne file, one or more plays
RoleReusable component — tasks, handlers, templates, defaultsDirectory structure
CollectionDistribution unit — roles, modules, plugins, docsGalaxy namespace

Idempotency

Ansible modules are designed to be idempotent — running a playbook multiple times produces the same result. The apt module with state: present installs a package only if it's not already installed. command and shell modules are exceptions — they always run. Use creates or when to make them conditional.

Task Execution Order & Strategies

Within a play, execution order is: pre_tasks roles tasks post_tasks. Handlers run after each section, not after each task. The serial keyword controls how many hosts run in parallel — essential for rolling updates.

Common Modules Reference

ModulePurposeExample
apt / yum / dnfPackage managementapt: name=nginx state=present
copy / templateFile deploymenttemplate: src=app.conf.j2 dest=/etc/app.conf
service / systemdService managementservice: name=nginx state=started enabled=yes
fileFile/directory attributesfile: path=/opt/app state=directory mode=0755
lineinfileEdit single lines in fileslineinfile: path=/etc/ssh/sshd_config regexp='^Port' line='Port 2222'
user / groupUser/group managementuser: name=deploy groups=sudo shell=/bin/bash
command / shellRun commands (not idempotent)command: cmd='make install' chdir=/opt/app
uriHTTP requestsuri: url=http://localhost/health status_code=200

Best Practices

  • Name every task — meaningful names make ansible-playbook -v output readable and debugging faster.
  • Use tags — tags let you run specific parts: ansible-playbook site.yml --tags deploy
  • Handlers for restarts — never restart a service in a task directly. Use notify to trigger a handler. Handlers only run once per play, even if notified multiple times.
  • Use Ansible Vault — never store passwords in plaintext. Use {{ vault_db_password }} and encrypt with ansible-vault encrypt_string.
  • Prefer modules over shell — modules are idempotent and cross-platform. command and shell should be a last resort.
  • Use roles for reusability — extract common tasks into roles. Structure: roles/nginx/tasks/main.yml.

Privacy First

All playbook generation happens entirely in your browser using JavaScript. Your hostnames, variables, credentials references, and infrastructure details are never sent to any server. This tool has zero backend dependencies.

Related Tools & Resources