Hi!
After reading the docs, dozens of group messages and several articles, I can’t find the way to locate playbooks in subdirs.
I’m having a large, complex project to deploy several and different installations in multiple hosts, and the amount of playbooks are growing up.
At this moment, everything works fine with my playbooks located at project’s root folder, but I’d like a little more organization
So I decided to create a playbooks folder and move them in some subdirectories inside.
Following this repository guideline, I created an ansible.cfg file with role_path=…/roles
This is my folder (re)structure
`
project
_ inventory
_ playbooks
_ ansible.cfg
|_ webservers.yml
|_ databases.yml`` `````|_ roles` ``|_ nginx`` ```|_ php``` ``````|_ mysql
`
But when I run
`
> ansible-playbook -i inventory plays/webservers.yml
`
it throws the error
`
ERROR! the role 'nginx' was not found in /Users/max/Work/project/playbooks/roles:/Users/max/Work/project/playbooks:/etc/ansible/roles
`
It seems that the role_path is not working, and I don't have any more ideas-
So my question is: is there a way to achieve subfolder organization to playbooks?
Thanks a lot for any help!
Max
Hi Max,
[...] but I'd like a little more organization
So I decided to create a *playbooks* folder and move them in some
subdirectories inside.
Isn't a vast number of tasks in the project's main folder a sign that
you aren't using roles enough?
Following this repository
<https://github.com/enginyoyen/ansible-best-practises> guideline, I created
an ansible.cfg file with role_path=../roles
roles_path not role_path -- but I guess it's just a typo in the mail.
http://docs.ansible.com/ansible/playbooks_roles.html
suggests to use a central location for all roles across projects and use
roles_path with one (absolute) path:
"
In Ansible 1.4 and later you can configure a roles_path to search for
roles. Use this to check all of your common roles out to one location,
and share them easily between multiple playbook projects. See
Configuration file for details about how to set this up in ansible.cfg.
"
Using recommendations and best practices from ansible.com has the
advantage that on-boarding others is relatively easy. You'll have a
single source to point them to.
Regards,
Benjamin
I agree that it’s annoying, especially if you try to organize by includes and reusable playbooks, it’s hard to tell, looking at a list of *.yml files which ones are the top-level and which are meant to be included.
If you’re not using roles and only using tasks, you can put your tasks in a tasks/ subfolder and then include them and everything will use the dir of the playbook as the ansible root.
However, if you’re using roles, the roles are assumed to be in a subdir of the playbook, so you can either create a playbooks/ subdir and reference your roles like:
./stuff.yml
`
Benjamin, Mike:
Thanks for your replies and your advices.
Now I know I need to reorganize a bit mi playboks and try to follow the Ansible best practices more closely.
Thanks in advance!!
Max