Server configuration as a list of tasks
Ansible playbooks are YAML lists of plays, each containing tasks that target hosts. The runtime sshes to each host and executes tasks in order, idempotently — re-running a playbook on an already-configured host is a no-op for unchanged tasks.
Five core sections
hosts:— which inventory group to target.vars:— playbook-scoped variables (or include fromvars/files).tasks:— ordered actions. Each is a module call (apt:,copy:,systemd:) with parameters.handlers:— fire onnotify:from a task. Run once at the end of the play, even if notified multiple times.roles:— reusable bundles of tasks, vars, files, templates.
Inventory — the hosts file
Inventory can be YAML, INI, or dynamic (cloud API plugin). YAML inventory groups hosts and assigns variables.
Principle: Ansible's value is idempotency. Every well-written task is 'declare desired state,' not 'run this command.' Reach for the dedicated module (
apt:, file:, systemd:) before falling back to shell: or command:. The dedicated module knows how to detect 'already done' and skip.