import_role from another directory

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!

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?

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

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

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>:

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:

Install ntp in project “lamp_simple”: 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

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