Ansible YAML Examples

2 practical Ansible YAML examples — an idempotent playbook that installs and configures Nginx on Ubuntu servers using FQCN modules and handlers, and a structured YAML inventory that organizes hosts into groups with per-host and per-group variables.

Ansible is an agentless IT automation tool that uses YAML files called playbooks to describe tasks to run on remote hosts over SSH. Playbooks are applied with ansible-playbook -i inventory.yml nginx.yml. Ansible's YAML format is strict — indentation errors can cause tasks to run under the wrong play or fail entirely. Ansible also uses YAML for inventory files, host variable files, role defaults, and more. Use the DotYAML validator to check YAML syntax before running your playbooks.

⚙️

Nginx Playbook

Install and configure Nginx on Ubuntu: apt install, Jinja2 template deployment, site enabling via symlink, and idempotent handlers.

Ansible
📋

Inventory File

YAML inventory with webservers, dbservers, and monitoring groups, per-host variables, and global connection settings.

Ansible

Also in the Examples Library

Kubernetes – Deployment Docker Compose – Single Service GitHub Actions – Deploy to AWS