Middle
How did you organize the storage of playbooks and roles in your project?
sobes.tech AI
Answer from AI
We used a monorepo to store playbooks and roles.
Repository structure:
.
├── roles/ // Directory for roles
│ ├── common/
│ │ ├── tasks/
│ │ ├── handlers/
│ │ └── files/
│ └── webserver/
│ ├── tasks/
│ └── templates/
└── playbooks/ // Directory for playbooks
├── site.yml // Main playbooks
├── web-servers.yml
├── db-servers.yml
└── inventory/ // Inventory
├── hosts.ini
└── group_vars/
├── all.yml
└── webservers.yml
- roles/: Each subdirectory inside
roles/represents a separate role. Roles contain tasks, handlers, templates, and files necessary for configuring a specific component or service. - playbooks/: Contains
.ymlplaybook files. These playbooks describe the sequence of role and task execution to achieve a desired infrastructure state. - inventory/: Stores information about the inventory servers where playbooks are executed.
hosts.ini: List of hosts.group_vars/: Variables specific to host groups.
Version control was managed with Git. Dependencies for roles were handled using requirements.yml and ansible-galaxy collection install for collection installation. Different environments (dev, stage, prod) were managed with separate inventory files or dynamic inventory.
Example of requirements.yml:
# collections
collections:
- name: community.general
# roles
roles:
- src: git@github.com:username/ansible-role-nginx.git
version: "1.0.0"
name: nginx