Ansible Playbook

An Ansible Playbook is a YAML file that describes the desired state of systems as an ordered list of plays. Each play targets a group of hosts from the inventory and runs tasks, where every task calls an Ansible module. Playbooks are Ansible’s main unit of automation.

Sample Ansible Playbook

- name: Install and start nginx
  hosts: webservers
  become: true
  tasks:
    - name: Install nginx
      ansible.builtin.dnf:
        name: nginx
        state: present

    - name: Start and enable nginx
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true

Run it with ansible-playbook -i inventory.yml site.yml. Useful options include --check (dry run), --diff, --limit and -e for extra variables.

Playbooks are now often drafted by AI coding assistants. Steampunk Spotter verifies them at commit and in CI/CD before they reach Red Hat AAP, with 82% fewer Playbook errors reported by Deutsche Telekom MMS.