Where Are Ansible Playbooks Stored? Default Paths & Best Practices
By Luca Berton · Published 2024-01-01 · Category: database-automation
Where to store Ansible playbooks: default paths, project structure, Git repositories, and organizational best practices for automation files.
Ansible playbooks are essential for defining automation workflows, and storing them in an organized and accessible manner is critical for efficient operations. This article explores where playbooks are typically stored, best practices for directory organization, and tips for effective management.
Where Are Ansible Playbooks Stored?
Ansible playbooks are YAML files that can be stored anywhere in the filesystem, as long as they are accessible to the Ansible control node. There is no mandatory default location, but best practices suggest using a structured directory layout.
Typical Locations for Playbooks
- Project-Specific Directories:
~/projects/ansible/playbooks/
- Centralized Repository:
/srv/ansible/playbooks/
- Role-Based Directories:
~/projects/ansible/roles/<role_name>/tasks/main.yml
Verifying Playbook Location
When running a playbook, specify its path:ansible-playbook /path/to/playbook.ymlSee also: Project Policy Validation with OPA and ansible-policy
Recommended Directory Structure
Organizing playbooks and associated files is crucial for scalability and maintainability. Below is a common directory structure:
ansible/
├── playbooks/
│ ├── site.yml # Entry point for playbooks
│ ├── webservers.yml # Playbook for web servers
│ └── dbservers.yml # Playbook for database servers
├── inventory/
│ ├── production # Production inventory
│ └── staging # Staging inventory
├── group_vars/
│ ├── all.yml # Variables for all groups
│ └── webservers.yml # Variables for web servers
├── host_vars/
│ ├── host1.yml # Variables for host1
│ └── host2.yml # Variables for host2
├── roles/
│ ├── webserver/ # Role for web server setup
│ │ └── tasks/
│ │ └── main.yml
│ └── database/ # Role for database setup
│ └── tasks/
│ └── main.yml
├── files/ # Static files
├── templates/ # Jinja2 templates
└── ansible.cfg # Configuration fileKey Components:
- Playbooks: Store the primary YAML files defining tasks.
- Inventory: Define target systems and groupings.
- Group/Host Variables: Organize variables for groups or individual hosts.
- Roles: Modularize tasks into reusable components.
Best Practices for Storing Playbooks
- Use Version Control:
- Follow Consistent Naming:
deploy_app.yml.
- Isolate Environments:
- Leverage Roles:
- Document Directory Structure:
Conclusion
Ansible playbooks can be stored anywhere, but using a structured directory layout ensures scalability, maintainability, and collaboration. By adhering to best practices, you can streamline your automation workflows and manage playbooks effectively.
Learn More About Ansible Playbooks
See also: What Are Ansible Playbooks? Definition, Structure, and Examples (2026 Guide)
Default Ansible Paths
| Path | Purpose |
|---|---|
/etc/ansible/ | System-wide default directory |
/etc/ansible/playbooks/ | Common shared playbooks location |
/etc/ansible/roles/ | System-wide roles |
~/.ansible/ | User-specific data |
~/.ansible/roles/ | User Galaxy roles |
~/.ansible/collections/ | User collections |
Best Practice: Git Repository
myorg-ansible/
ansible.cfg
inventory/
production/
hosts.yml
group_vars/
staging/
hosts.yml
playbooks/
site.yml
webservers.yml
roles/
common/
webserver/
README.mdansible.cfg Search Order
$ANSIBLE_CONFIG(environment variable)./ansible.cfg(current directory)~/.ansible.cfg(home directory)/etc/ansible/ansible.cfg(system-wide)
Team Organization Patterns
Single repo (small teams)
All playbooks, roles, and inventory in one repo.
Multi-repo (large teams)
ansible-roles/- Shared rolesansible-environments/- Environment configsansible-deploy/- Deployment playbooks
AWX/AAP
Playbooks stored in Git Projects that sync automatically.
See also: Ansible Variables: Complete Guide to vars, facts & Precedence
Finding Playbooks on a System
find / -name "*.yml" -exec grep -l "hosts:" {} \; 2>/dev/null
ansible-config dump | grep -i "default_roles_path\|inventory"FAQ
Should I use /etc/ansible/ for production?
No - use Git. It provides version control, code review, and rollback.
How does AWX find playbooks?
AWX syncs from Git repos configured as Projects, scanning for playbooks in the project root.
Related Articles
Category: database-automation