# import\_role from another directory

**URL:** <https://forum.ansible.com/t/import-role-from-another-directory/30912>\
**Category:** Ansible Project\
**Created:** [July 31, 2019, 6:16am UTC](https://forum.ansible.com/t/import-role-from-another-directory/30912 "2019-07-31T06:16:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [July 31, 2019, 6:16am UTC](https://forum.ansible.com/t/import-role-from-another-directory/30912/1 "2019-07-31T06:16:10Z")

</div>

Hello team!

My directory ansible-repo follow:

├── base  
│ ├── group\_vars  
│ │ └── all  
│ ├── roles  
│ │ └── common  
│ │ ├── handlers  
│ │ │ └── main.yml  
│ │ ├── tasks  
│ │ │ └── main.yml  
│ │ └── templates  
│ │ └── ntp.conf.j2  
│ └── site.yml  
├── lnmp\_standalone  
│ ├── group\_vars  
│ ├── roles  
│ └── site.yml

I have a “base” directory which installing base things like monitoring, ntp, etc. Which we need almost on all our servers.

Directory “lnmp\_standalone” will install Nginx, Php-Fpm, MySql on linux. But it also mean “base” things like monitoring, ntp should be installed. Without copying tasks from “base” directory to “lnmp\_standalone” and maintain all versions of copied files, have the ansible a functional of importing role from another dir?

I see “import\_role” function will import only from “roles” subdirectory from where you start your playbook. For example if I would be in “lnmp\_standalone” dir and run:

ansible-playbook site.yml

It will look for import role only from subdirectory “roles”. Or I am wrong? And there is a way importing from …/…/base/roles?

Thank you!

---

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [July 31, 2019, 6:20am UTC](https://forum.ansible.com/t/import-role-from-another-directory/30912/2 "2019-07-31T06:20:48Z")

</div>

If import\_role cannot look to level up directories how we can avoid repeating myself with again and again writing base things which want to be included on all roles?

---

<div class="post-metadata">

**Author:** ![Kunalsing\_Thakur](https://avatars.discourse-cdn.com/v4/letter/k/3d9bf3/32.png) [@Kunalsing\_Thakur](https://forum.ansible.com/u/Kunalsing_Thakur)\
**Post date:** [July 31, 2019, 7:06am UTC](https://forum.ansible.com/t/import-role-from-another-directory/30912/3 "2019-07-31T07:06:37Z")

</div>

you can set in ansible.cfg to look up for roles.

---

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [July 31, 2019, 7:37am UTC](https://forum.ansible.com/t/import-role-from-another-directory/30912/4 "2019-07-31T07:37:08Z")

</div>

I know it. But i feel from one project to another I will want include each time different roles. For example in project configures web server i want include monitoring role from

…/monitoring/roles

In another project i want include roles from

…/base/roles

Maybe i wrong understand. But from my point of view, and how ansible show it in examples:

[https://github.com/ansible/ansible-examples?files=1](https://github.com/ansible/ansible-examples?files=1)

Each folder configuring separate application. For example: lamp\_standalone install apache, and lamp\_haproxy also install apache. But it is dublication. Maybe better will have one place where we will have task for install apache and include it appropriate to lampfstandalone and to lamp\_haproxy?

We will no need maintain install apache task in several places.

ср, 31 июл. 2019 г., 9:06 Kunalsing Thakur \<[bits.kunalsing@gmail.com](mailto:bits.kunalsing@gmail.com)\>:

---

<div class="post-metadata">

**Author:** ![user89](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@user89](https://forum.ansible.com/u/user89)\
**Post date:** [July 31, 2019, 8:25am UTC](https://forum.ansible.com/t/import-role-from-another-directory/30912/5 "2019-07-31T08:25:43Z")

</div>

Maybe better my question can be:  
How we can avoid duplication playbooks from one project to another like we can see on ansible example [repo](https://github.com/ansible/ansible-examples):

Install ntp in project “lamp\_simple”: [https://github.com/ansible/ansible-examples/blob/master/lamp\_simple/roles/common/tasks/main.yml](https://github.com/ansible/ansible-examples/blob/master/lamp_simple/roles/common/tasks/main.yml)

Again install ntp in project “lamp\_haproxy”: [https://github.com/ansible/ansible-examples/blob/master/lamp\_haproxy/roles/common/tasks/main.yml](https://github.com/ansible/ansible-examples/blob/master/lamp_haproxy/roles/common/tasks/main.yml)

ср, 31 июл. 2019 г. в 09:37, Михаил Политаев \<[nisyarazh@gmail.com](mailto:nisyarazh@gmail.com)\>:
