# Playbook directory organisation

**URL:** <https://forum.ansible.com/t/playbook-directory-organisation/18603>\
**Category:** Ansible Project\
**Created:** [June 25, 2015, 10:22am UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603 "2015-06-25T10:22:43Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [June 25, 2015, 10:22am UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/1 "2015-06-25T10:22:43Z")

</div>

Hi,

This has probably been covered before but I can’t find any solutions.

My project pulls in roles from other projects via Maven. This means that we can have company wide roles reused.

This all works fine, all the roles are dropped into a subdirectory in roles and referenced in the playbooks.

I would like do something similar with playbooks. Whilst I can reference roles using …/roles/rolename inside a playbook in a subdirectory

None of the group\_vars that are available to the top level playbooks are available to the playbook in the subdirectory

Has anybody solved this or is there a better way of organising playbooks.

Any help appreciated

Thanks

---

<div class="post-metadata">

**Author:** ![cruz.pitre](https://avatars.discourse-cdn.com/v4/letter/c/82dd89/32.png) [@cruz.pitre](https://forum.ansible.com/u/cruz.pitre)\
**Post date:** [June 26, 2015, 5:57am UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/2 "2015-06-26T05:57:44Z")

</div>

Hi James,

Have you set the ansible configuration file’s (ansible.cfg) roles\_path default setting?  
See: [https://docs.ansible.com/intro\_configuration.html#roles-path](https://docs.ansible.com/intro_configuration.html#roles-path)

If you are following the best practices documented ([https://docs.ansible.com/intro\_configuration.html#roles-path](https://docs.ansible.com/intro_configuration.html#roles-path)), it should be pulling in those group\_vars variables, if the host(s) being applied to the plays/playbooks are within the defined groups that contain the variables.

Where is the group\_vars folder relative to the playbooks that are not “seeing” the variables?

To further confirm, please post an example in pastebin.

Thanks,

Cruz

---

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [June 26, 2015, 3:03pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/3 "2015-06-26T15:03:13Z")

</div>

Hi,

Thanks for the info. I hadn’t looked at those configs, though we can only change the configuration on certain environments.

My layout is pretty straightforward

.  
├── group\_vars  
│ └── all.yml

└── roles  
│ ├── roleA  
│ ├── roleB  
│ └── shared\_roles  
│ ├── roleC  
│ └── roleD

├── playbook1.yml \<---- these pick up the group\_vars  
├── playbook2.yml  
├── playbook3.yml  
├── playbook\_sub\_dir  
│ ├── playbook4.yml \<---- these don’t pick up the group\_vars  
│ ├── playbook5.yml  
│ └── playbook6.yml

I’ll try and knock together an example. I can’t include the actual project as there is a fair amount of sensitive information…

The issue is just with the playbooks in the sub directories. I can get them to hit the roles by referencing them with …/ its just the group\_vars that aren’t getting picked up

Im just looking to organise the playbooks as im starting to get a lot in the root directory

Thanks

James

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [June 26, 2015, 3:16pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/4 "2015-06-26T15:16:48Z")

</div>

Group vars can sit next to your inventory or next to your playbook. Looks like your current groupvars are evaluated because they sit next to yout root-dir playbooks.

You can try to put them next to your inventory so that they’ll be evaluated for every pkaybook that’s run with that inventory.

---

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [June 26, 2015, 3:28pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/5 "2015-06-26T15:28:09Z")

</div>

Ok that makes sense but causes a problem for my layout. I have

.  
├── group\_vars  
│ ├── all.yml  
│ ├── groupA.yml  
│ ├── groupB.yml  
│ └── groupC.yml  
├── inventory  
│ └── ec2  
│ ├── eu-west  
│ │ ├── inventoryA  
│ │ └── inventoryB  
│ └── us-east  
│ ├── inventoryA  
│ └── inventoryB

There are many inventories. Currently I have all plays use the groups defined in the main group\_vars. If I was to move some common groups\_vars to the inventory then they would be duplicated for each inventory. Unless im missing something

I was hoping there would be a way of having ansible look at the playbook\_dir instead of its current dir when evaluating the group\_vars.

J

---

<div class="post-metadata">

**Author:** ![Hagai\_Kariti](https://avatars.discourse-cdn.com/v4/letter/h/4491bb/32.png) [@Hagai\_Kariti](https://forum.ansible.com/u/Hagai_Kariti)\
**Post date:** [June 26, 2015, 4:08pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/6 "2015-06-26T16:08:22Z")

</div>

There was another thread about that yesterday. No good option that i know of. You can try to create a link to your var files inside each invetory, or write another inventory script that includes these files.

---

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [June 26, 2015, 4:10pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/7 "2015-06-26T16:10:33Z")

</div>

Ok,

I think i’d prefer more playbooks in the playbook\_dir rather than resorting to symlinks. Less likely to confuse or go wrong.

Cheers for the info

J

---

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [June 26, 2015, 4:45pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/8 "2015-06-26T16:45:07Z")

</div>

Discussed here: [https://groups.google.com/forum/#!topic/ansible-project/T9RWNQbLRWs](https://groups.google.com/forum/#!topic/ansible-project/T9RWNQbLRWs)

---

<div class="post-metadata">

**Author:** ![James\_Morgan1](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan1](https://forum.ansible.com/u/James_Morgan1)\
**Post date:** [June 28, 2015, 10:53am UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/9 "2015-06-28T10:53:23Z")

</div>

Interesting read though that seems to concern itself with the group\_var / inventory layouts. I don't really have a problem there. Just the playbook sub directories not picking up the variables. If I ignore the idea of tidying playbooks by sub directory everything works well. Symlinks seem a bit dirty and error prone, though as mentioned they would be preserved by git which could work as long as they are relative.

I'll have a play. Thanks for all the advice

J

---

<div class="post-metadata">

**Author:** ![Tom\_Paine](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tom\_Paine](https://forum.ansible.com/u/Tom_Paine)\
**Post date:** [June 30, 2015, 12:15am UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/10 "2015-06-30T00:15:59Z")

</div>

Have updated that thread with an inventory script that can pick up any  
YAML vars files you'd like.

---

<div class="post-metadata">

**Author:** ![James\_Morgan](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@James\_Morgan](https://forum.ansible.com/u/James_Morgan)\
**Post date:** [June 30, 2015, 2:41pm UTC](https://forum.ansible.com/t/playbook-directory-organisation/18603/11 "2015-06-30T14:41:07Z")

</div>

Interesting, thanks for the info will have a play with it.
