# Scaling the Ansible Hierarchy?

**URL:** <https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064>\
**Category:** Ansible Project\
**Created:** [November 21, 2016, 3:38pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064 "2016-11-21T15:38:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [November 21, 2016, 3:38pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/1 "2016-11-21T15:38:13Z")

</div>

Hello,

I am currently following the [directory layout](http://docs.ansible.com/ansible/playbooks_best_practices.html#directory-layout) provided by Ansible.

I understand that if I keep all of my roles/\* in a directory, I can easily call each role from the top level directory like so:

`site.yml # master playbook webservers.yml # playbook for webserver tier dbservers.yml # playbook for dbserver tier`

**However, if I have more than just webservers, dbservers, etc. my top level directory will get filled with yml files like so:**

`  
site.yml # master playbook  
webservers.yml # playbook for webserver tier  
dbservers.yml # playbook for dbserver tier  
appservers.yml # playbook for appserver tier  
logservers.yml # playbook for logserver tier  
otherservers1.yml # playbook for otherservers1 tier  
otherservers2.yml # playbook for otherservers2 tier  
otherservers3.yml # playbook for otherservers3 tier  
otherservers4.yml # playbook for otherservers4 tier

roles/  
common/ # this hierarchy represents a “role”  
tasks/ #  
main.yml # ← tasks file can include smaller files if warranted  
handlers/ #  
main.yml # ← handlers file  
templates/ # ← files for use with the template resource  
ntp.conf.j2 # \<------- templates end in .j2  
files/ #  
bar.txt # ← files for use with the copy resource  
foo.sh # ← script files for use with the script resource  
vars/ #  
main.yml # ← variables associated with this role  
defaults/ #  
main.yml # ← default lower priority variables for this role  
meta/ #  
main.yml # ← role dependencies

`

**Question** : What is the solution to not overfilling my top-level directory with yml files? (Or is this normal?)

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 22, 2016, 5:37pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/2 "2016-11-22T17:37:24Z")

</div>

At you top level, create a directory called playbooks (or choose you  
favorite name). Then you can run "ansible-playbook playbooks/site.yml".

Since Ansible look for roles relative too where the playbook is, you  
need to set the "roles\_path = ./roles" in your ansible.cfg.

The ansible.cfg can live in your top level directory.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [November 22, 2016, 6:40pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/3 "2016-11-22T18:40:24Z")

</div>

Thank you, Kai! That works for me!

---

<div class="post-metadata">

**Author:** ![burns498](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@burns498](https://forum.ansible.com/u/burns498)\
**Post date:** [November 22, 2016, 6:53pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/4 "2016-11-22T18:53:02Z")

</div>

Thanks for the info! I tried this in my own environment, since I actually had a similar question before.

Moved playbooks to a playbooks dir. Set role\_path=./roles. This broke my include statements, which I now modified to ‘- include: “{{ roles\_path }}/role\_handlers\_ant/handlers/main.yml”’. This is likely a better practice anyway.

However, it seems that my plays can no longer find my group\_vars and other such objects. Basic structure is below:

`  
ansible.cfg  
.ansible/inventory

playbooks/  
pb.yml  
roles/

# roles…

host\_vars/

# host\_vars…

group\_vars/

# group\_vars…

`

Should host and group vars also be moved? They worked fine before I moved playbooks from top level dir to their own dir.

Specifically, the error I get now is below. This is a variable defined in a group\_vars.

> fatal: [ptl01a0fap006]: FAILED! =\> {“failed”: true, “msg”: “The conditional check ‘’{{ ansible\_user\_id }}’ != ‘{{ wmadmin }}’’ failed. The error was: error while evaluating conditional (‘{{ ansible\_user\_id }}’ != ‘{{ wmadmin }}’): ‘wmadmin’ is undefined\n\nThe error appears to have been in ‘/manh/roles/role\_utility\_preplay\_validation/tasks/main.yml’: line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n—\n- name: Ensure uid is appropriate for {{ inventory\_hostname\_short }}\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with\_items:\n - {{ foo }}\n\nShould be written as:\n\n with\_items:\n - "{{ foo }}"\n”}

Thanks

---

<div class="post-metadata">

**Author:** ![burns498](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@burns498](https://forum.ansible.com/u/burns498)\
**Post date:** [November 22, 2016, 7:25pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/5 "2016-11-22T19:25:08Z")

</div>

Ok so I ended up rolling back to playbooks in the top level directory.

I got myself turned around a bit here. The {{roles\_path}} as part of the include actually wasn’t working; which, I should have known since you can’t use ansible.cfg parameters in tasks like that. I think my main problem is that I’m using ‘include’ statements to include roles during plays. In this way, I function them out as reusable functions for different roles. I was warned that this is a nonstandard, in favor of meta dependencies. I think that’s coming back to bite me now.

Sample:

`

- name: database param\_def select

# Initial select statement to see if db changes are required

tags: db  
include: roles/role\_utility\_sqlplus/tasks/main.yml  
vars:  
query\_type: “select”  
table: “param\_def”  
filename: “dbselect\_paramdef\_mhe.sql”

`

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Wen](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@Jeffrey\_Wen](https://forum.ansible.com/u/Jeffrey_Wen)\
**Post date:** [November 22, 2016, 7:29pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/6 "2016-11-22T19:29:21Z")

</div>

When you run the ansible-playbook, what about prefixing the command with ANSIBLE\_ROLES\_PATH.

For example:

`ANSIBLE_ROLES_PATH=your_path ansible-playbook site.yml`

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 22, 2016, 8:34pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/7 "2016-11-22T20:34:35Z")

</div>

Ansible is looking for host\_vars and group\_vars in the inventory file  
directory or the playbook directory.  
If they exist in both, playbook directory overrides.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [November 22, 2016, 8:41pm UTC](https://forum.ansible.com/t/scaling-the-ansible-hierarchy/23064/8 "2016-11-22T20:41:05Z")

</div>

You could use  
include: ../roles/role\_utility\_sqlplus/tasks/main.yml

Or you could set roles\_path to a absolute path instead, but then the  
problem is that every Ansible users need to have the files in the same  
path and thats unpractical.
