Repository: ansible/ansible-lint

Issue:
ansible-lint not processing include with relative directory same as ansible
# Issue Type
- Bug report
# Ansible and Ansible Lint details

```
ansible 2.1.0.0
ansible-lint 2.7.1
```
- ansible installation method: pip
- ansible-lint installation method: pip
# Desired Behaviour

`ansible-lint` is able to parse relative include statements within roles the same as `ansible`
# Actual Behaviour (Bug report only)

`ansible-lint` uses role directory as base when following an include statement.
`ansible` uses the playbook directory as base when following an include statement
## playbook

{{playbook_dir}}/test-include.yml

``` YAML

---
- hosts: localhost
  connection: local
  roles:
    - test-role
```

{{playbook_dir}}/roles/test-role/tasks/main.yml

``` YAML

---
   - name: Include playbook from another role
     include: roles/include-role/tasks/main.yml
```

{{playbook_dir}}/roles/include-role/tasks/main.yml

``` YAML

---
   - debug: msg="Test including an include role"
```
## output from ansible

```
PLAY [localhost] ***************************************************************

TASK [setup] *******************************************************************
ok: [127.0.0.1]

TASK [test-role : Include playbook from another role] **************************
included: /apps/dev/playbooks/ant/lint-include/roles/include-role/tasks/main.yml for 127.0.0.1

TASK [test-role : debug] *******************************************************
ok: [127.0.0.1] => {
    "msg": "Test including an include role"
}

PLAY RECAP *********************************************************************
127.0.0.1                  : ok=3    changed=0    unreachable=0    failed=0
```
## output of running ansible-lint (test-include.yml)

```
WARNING: Couldn't open /apps/dev/playbooks/ant/lint-include/roles/test-role/tasks/roles/include-role/tasks/main.yml - No such file or directory
```



Discussion:
Just tested adding the {{ playbook_dir }} to the include to stop making it relative.. Same result.
{{playbook_dir}}/roles/test-role/tasks/main.yml

``` YAML
---
   - name: Include playbook from another role
     include: "{{ playbook_dir }}/roles/include-role/tasks/main.yml"
```

Same thing with "global" tasks included in roles.
If, in "{{ playbook_dir }}/roles/foo/tasks/main.yml", I include bar.yml, Ansible seeks inside "{{ playbook_dir }}/tasks/" if not found in "{{ playbook_dir }}/roles/foo/tasks/", but ansible-lint not.

Works in ansible but not in ansible-lint:

```
$ tree
├── roles
│   └── foo
│       └── tasks
│           └── main.yml
└── tasks
    └── bar.yml
```

```
---
# File: roles/foo/tasks/main.yml
- include: bar.yml
```

Any plans to address this?
If people find a fix for this, with passing tests, I'll look at incorporating it.
I don't suppose the last update to this has changed now that ansible-lint is part of Ansible proper?
As in version of  `ansible-lint 4.1.0` it's not fixed yet.
Where would I start if I want to implement that? 
I am using Ansible patched with this PR: https://github.com/ansible/ansible/pull/58725

I achieved to make it work with the following syntax
```
    - name: Load environment
      include_tasks: tasks/load_environment.yml
      args:
        tags:
          - always
```

Please note it will always fail to find the file if using `file` key.

The whole problem is related to https://github.com/ansible/ansible-lint/issues/507 that is still not fixed for 2.8 version.


Resolving patch:
diff --git a/lib/ansiblelint/utils.py b/lib/ansiblelint/utils.py
--- a/lib/ansiblelint/utils.py
+++ b/lib/ansiblelint/utils.py
@@ -52,6 +52,8 @@
 # successfully.
 DEFAULT_VAULT_PASSWORD = 'x'
 
+PLAYBOOK_DIR = os.environ.get('ANSIBLE_PLAYBOOK_DIR', None)
+
 
 def parse_yaml_from_file(filepath):
     dl = DataLoader()
@@ -210,7 +212,7 @@ def play_children(basedir, item, parent_type, playbook_dir):
         if v:
             v = template(os.path.abspath(basedir),
                          v,
-                         dict(playbook_dir=os.path.abspath(basedir)),
+                         dict(playbook_dir=PLAYBOOK_DIR or os.path.abspath(basedir)),
                          fail_on_undefined=False)
             return delegate_map[k](basedir, k, v, parent_type)
     return []


Test patch: