# Playbook relative role\_paths

**URL:** <https://forum.ansible.com/t/playbook-relative-role-paths/25692>\
**Category:** Ansible Project\
**Created:** [October 6, 2017, 2:27am UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692 "2017-10-06T02:27:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_Parrish](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeff\_Parrish](https://forum.ansible.com/u/Jeff_Parrish)\
**Post date:** [October 6, 2017, 2:27am UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/1 "2017-10-06T02:27:58Z")

</div>

Given an ansible structure below

├── ansible.cfg  
├── deploy.yml  
├── files/  
├── foundation\_roles/  
│ ├── cleanup/  
│ ├── common/  
│ ├── deploy/  
│ ├── retire/  
│ └── setup/  
├── group\_vars/  
├── roles/  
│ └── service/

I would like to be able to refer to the roles in “foundation\_roles” without having to use relative references everywhere. In particular, the roles in “foundation\_roles” need to reference each other.

I believe one elegant solution would be to use the role\_paths configuration setting - IF you could specify a path that was relative to the playbook\_dir. However, as far as I can tell, these paths need to be absolute, or they are relative to the directory from which ansible was invoked.

Is this possible, and I’m just missing it?

---

<div class="post-metadata">

**Author:** ![Cev\_Ing](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@Cev\_Ing](https://forum.ansible.com/u/Cev_Ing)\
**Post date:** [October 6, 2017, 11:31am UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/2 "2017-10-06T11:31:22Z")

</div>

We use relative paths:

roles\_path = ./roles

They are relative to the directory in which you execute ansible-playbook.

---

<div class="post-metadata">

**Author:** ![Jeff\_Parrish](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeff\_Parrish](https://forum.ansible.com/u/Jeff_Parrish)\
**Post date:** [October 6, 2017, 4:24pm UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/3 "2017-10-06T16:24:44Z")

</div>

The issue is that the relative path is relative to where the playbook was invoked, not relative to the playbook. That means that every invocation must be from the same relative depth - which is not necessarily the case when the roles are being shared by lots of people and automation. For example, we have build automation that tends to nest the ansible playbooks quite deeply.

For example the relative path in the roles\_path directory would cause at least one of the following cases to fail:  
1. Ansible-playbook /a/b/c/pb.yml  
2. Ansible-playbook /x/pb.yml

where the actual directory names are irrelevant, only the depth matters.

I think the real question is in what cases would current ansible code break if the relative role\_paths were defined to be relative to the playbook\_dir?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 6, 2017, 4:28pm UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/4 "2017-10-06T16:28:11Z")

</div>

The path should be relative to the config file (it has not always  
been, but fixed in 2.4 to ensure this).

IF you want it otherwise you can use the {{CWD}} macro to change that behaviour.

roles/ is already looked at relative to the playbook path, but not  
ROLES\_PATH as that is a global setting.

---

<div class="post-metadata">

**Author:** ![Jeff\_Parrish](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeff\_Parrish](https://forum.ansible.com/u/Jeff_Parrish)\
**Post date:** [October 6, 2017, 6:54pm UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/5 "2017-10-06T18:54:35Z")

</div>

Thanks, Brian. Let me make sure I understand.

“The path should be relative to the config file (it has not always been, but fixed in 2.4 to ensure this).”

Which path? And do you mean “ansible.cfg”. I’m currently running ansible 2.3.1, so that may be the source of my problems.

If, as of 2.4, the path from which relative paths in ROLES\_PATH are calculated is the directory containing ansible.cfg, that will resolve my issue nicely.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 6, 2017, 7:37pm UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/6 "2017-10-06T19:37:49Z")

</div>

any path defined inside the ansible.cfg shoudl be relative to the file.

---

<div class="post-metadata">

**Author:** ![Jeff\_Parrish](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeff\_Parrish](https://forum.ansible.com/u/Jeff_Parrish)\
**Post date:** [October 9, 2017, 11:52pm UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/7 "2017-10-09T23:52:37Z")

</div>

I don’t see that paths inside ansible.cfg are relative to the config file itself.

The structure of my ansible files in /a/b/c/d/e/ansible is:

ansible.cfg  
setup.yml  
roles  
foundation\_roles  
&nbsp;&nbsp;&nbsp;&nbsp;setup  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;main.yml

The “roles\_path” is set to “./foundation\_roles in ansible.cfg

Executing “ansible-playbook -vvv ansible/setup.yml” from the “/a/b/c/d/e” directory produces:

ansible-playbook 2.4.0.0  
&nbsp;&nbsp;&nbsp;config file = /a/b/c/d/e/ansible/ansible.cfg  
&nbsp;&nbsp;&nbsp;python version = 2.7.13 (default, Feb 2 2017, 13:41:18) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)]  
Using /a/b/c/d/e/ansible/ansible.cfg as config file

ERROR! the role 'setup' was not found in /a/b/c/d/e/ansible/roles:/a/b/c/d/e/foundation\_roles:/a/b/c/d/e/ansible

It appears that the paths are relative to the directory from which ansible was invoked. What am I missing?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [October 10, 2017, 2:51pm UTC](https://forum.ansible.com/t/playbook-relative-role-paths/25692/8 "2017-10-10T14:51:04Z")

</div>

You are correct, my bad, thought i had fixed that, in any case, this  
PR should [https://github.com/ansible/ansible/issues/31533](https://github.com/ansible/ansible/issues/31533)
