AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,400 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of 8 Ansible books published by Apress and Leanpub including "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example", and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

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: Playbooks are often stored in project directories for better organization:
   ~/projects/ansible/playbooks/
   
Centralized Repository: Teams may use a shared repository or version-controlled directory:
   /srv/ansible/playbooks/
   
Role-Based Directories: When using roles, playbooks are stored alongside roles for modularity:
   ~/projects/ansible/roles/<role_name>/tasks/main.yml
   

Verifying Playbook Location

When running a playbook, specify its path:
ansible-playbook /path/to/playbook.yml

See also: Project Policy Validation with OPA and ansible-policy

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 file

Key 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: Store playbooks in a Git repository to track changes and collaborate effectively. Follow Consistent Naming: Use descriptive names for playbooks to indicate their purpose, e.g., deploy_app.yml. Isolate Environments: Separate playbooks and inventories for production, staging, and development environments. Leverage Roles: Break down playbooks into roles for modularity and reuse. Document Directory Structure: Provide a README file in the project directory to explain the organization.

See also: What Are Ansible Playbooks? Definition, Structure, and Examples (2026 Guide)

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

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 |

See also: Ansible Variables: Complete Guide to vars, facts & Precedence

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.md

ansible.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 roles • ansible-environments/ - Environment configs • ansible-deploy/ - Deployment playbooks

AWX/AAP

Playbooks stored in Git Projects that sync automatically.

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

Ansible template vs copy modulemanaging inventory in Ansiblerole variables and defaults in Ansible

Category: database-automation

Browse all Ansible tutorials · AnsiblePilot Home