Repository: ansible/ansible-lint

Issue:
Assertion fail for include in a block
# Issue Type
- Bug report

# Ansible and Ansible Lint details

```
ansible 2.2.0.0
ansible-lint 3.4.8
```

- ansible installation method: custom
- ansible-lint installation method: pip

# Desired Behaviour
Check with default ruleset without any message

# Actual Behaviour (Bug report only)
```
Traceback (most recent call last):
  File "/home/robin/.local/bin/ansible-lint", line 9, in <module>
    load_entry_point('ansible-lint==3.4.8', 'console_scripts', 'ansible-lint')()
  File "/home/robin/.local/lib/python2.7/site-packages/ansiblelint/main/__init__.py", line 121, in main
    matches.extend(runner.run())
  File "/home/robin/.local/lib/python2.7/site-packages/ansiblelint/__init__.py", line 231, in run
    for child in ansiblelint.utils.find_children(arg, self.playbook_dir):
  File "/home/robin/.local/lib/python2.7/site-packages/ansiblelint/utils.py", line 158, in find_children
    for child in play_children(basedir, item, playbook[1], playbook_dir):
  File "/home/robin/.local/lib/python2.7/site-packages/ansiblelint/utils.py", line 207, in play_children
    return delegate_map[k](basedir, k, v, parent_type)
  File "/home/robin/.local/lib/python2.7/site-packages/ansiblelint/utils.py", line 230, in _taskshandlers_children
    assert(parent_type == 'playbook')
AssertionError
```

The failing assert is in
https://github.com/willthames/ansible-lint/blob/ae8a8d3bef17b2cad888517b38b16f29b0273521/lib/ansiblelint/utils.py#L228
and was introduced in ae8a8d3bef17b2cad888517b38b16f29b0273521 by @MartinNowak and @willthames 

When that assertion is failing the values of 
`th, k, v, parent_type` are `({u'include': u'repos.yml'}, u'block', [{u'include': u'repos.yml'}], 'tasks')`

The code is in tasks of a role `role/foo/tasks/main.yml`:
```
- block:
  - include: repos.yml
  tags: repos
```
We use(d) that in several places to tag subsections of a role. Ansible-playbook parses it correctly.
If I remember correctly some time ago `include` did not allow tags. With ansible 2.2.0 one can put the tags directly on the include, but blocks with include are valid ansible and should thus not lead to an assertionerror in ansible-lint.

Let me know if you need more details. 


Discussion:
This is a great bug report, thanks - I shouldn't need more than this but I'll let you know if I do.

Resolving patch:
diff --git a/lib/ansiblelint/utils.py b/lib/ansiblelint/utils.py
--- a/lib/ansiblelint/utils.py
+++ b/lib/ansiblelint/utils.py
@@ -222,11 +222,13 @@ def _taskshandlers_children(basedir, k, v, parent_type):
     results = []
     for th in v:
         if 'include' in th:
-            # taskshandlers_children only get's called for playbooks, thus the
+            # when taskshandlers_children is called for playbooks, the
             # actual type of the included tasks is the section containing the
             # include, e.g. tasks, pre_tasks, or handlers.
-            assert(parent_type == 'playbook')
-            playbook_section = k
+            if parent_type == 'playbook':
+                playbook_section = k
+            else:
+                playbook_section = parent_type
             results.append({
                 'path': path_dwim(basedir, th['include']),
                 'type': playbook_section


Test patch: