Repository: ansible/ansible-lint

Issue:
Incorrect type guessing for an included playbook
# Issue Type
- Bug report

# Ansible and Ansible Lint details

```
➜ ansible --version
ansible 2.8.7
  config file = /home/bvergnaud/git/gitlab.infra.online.net/platform/ansible-playbooks/ansible.cfg
  configured module search path = ['/home/bvergnaud/git/gitlab.infra.online.net/platform/ansible-playbooks/library', '/home/bvergnaud/git/gitlab.infra.online.net/platform/ansible-playbooks/library/foreman/plugins/modules']
  ansible python module location = /home/bvergnaud/.local/share/virtualenvs/ansible-playbooks-VBzdj4yE/lib/python3.8/site-packages/ansible
  executable location = /home/bvergnaud/.local/share/virtualenvs/ansible-playbooks-VBzdj4yE/bin/ansible
  python version = 3.8.0 (default, Oct 23 2019, 18:51:26) [GCC 9.2.0]

~/git/gitlab.infra.online.net/platform/ansible-playbooks on  master [$!?] via 🐍 v3.8.0 (ansible-playbooks-VBzdj4yE) 
➜ ansible-lint --version
ansible-lint 4.2.0rc1
```

- ansible installation method: pip
- ansible-lint installation method: pip

# Desired Behaviour

When importing a playbook from within another playbook, ansible-lint should properly guess that it is a type playbook.

# Actual Behaviour (Bug report only)

When you include a playbook in the pre-tasks sections (we need that secondary playbook to play before the roles) the linter guess its type as 'pre_tasks', and reports the following error multiple times in my case (I didn't manage to find what the number of error is based on): `Error trying to append skipped rules: RuntimeError('Unexpected file type: pre_tasks')`.

Example playbook1.yml :
```
---
- name: Do something
  hosts: "some_host"
  pre_tasks:
    - name: Do something before the roles
      include: playbook2.yml

  roles:
    - role1
```

The included `playbook2.yml` is another playbook right next to the first one, and could contain anything.
The error does not cause the return code to change which is lucky in my case as I'm trying to bake it in the pre-commit routine.


Discussion:
@bvergnaud did it work in 4.1?
Yes it did. However the 4.1 will not install from source, in pre-commit.
https://github.com/ansible/ansible-lint/issues/590
@ssbarnea @awcrosby ^

Resolving patch:
diff --git a/lib/ansiblelint/utils.py b/lib/ansiblelint/utils.py
--- a/lib/ansiblelint/utils.py
+++ b/lib/ansiblelint/utils.py
@@ -614,7 +614,7 @@ def _append_skipped_rules(pyyaml_data, file_text, file_type):
     if file_type in ('tasks', 'handlers'):
         ruamel_task_blocks = ruamel_data
         pyyaml_task_blocks = pyyaml_data
-    elif file_type == 'playbook':
+    elif file_type in ('playbook', 'pre_tasks', 'post_tasks'):
         try:
             pyyaml_task_blocks = _get_task_blocks_from_playbook(pyyaml_data)
             ruamel_task_blocks = _get_task_blocks_from_playbook(ruamel_data)


Test patch:
diff --git a/test/TestPretaskIncludePlaybook.py b/test/TestPretaskIncludePlaybook.py
new file mode 100644
--- /dev/null
+++ b/test/TestPretaskIncludePlaybook.py
@@ -0,0 +1,35 @@
+import os
+import unittest
+
+from ansiblelint import Runner, RulesCollection
+
+
+class TestTaskIncludes(unittest.TestCase):
+
+    def setUp(self):
+        rulesdir = os.path.join('lib', 'ansiblelint', 'rules')
+        self.rules = RulesCollection.create_from_directory(rulesdir)
+
+    def test_pre_task_include_playbook(self):
+        filename = 'test/playbook-include/playbook_pre.yml'
+        runner = Runner(self.rules, filename, [], [], [])
+        results = runner.run()
+
+        self.assertEqual(len(runner.playbooks), 2)
+        self.assertEqual(len(results), 3)
+        self.assertIn('Commands should not change things', str(results))
+
+        self.assertNotIn('502', str(results))
+        self.assertNotIn('All tasks should be named', str(results))
+
+    def test_post_task_include_playbook(self):
+        filename = 'test/playbook-include/playbook_post.yml'
+        runner = Runner(self.rules, filename, [], [], [])
+        results = runner.run()
+
+        self.assertEqual(len(runner.playbooks), 2)
+        self.assertEqual(len(results), 3)
+        self.assertIn('Commands should not change things', str(results))
+
+        self.assertNotIn('502', str(results))
+        self.assertNotIn('All tasks should be named', str(results))
diff --git a/test/playbook-include/playbook_included.yml b/test/playbook-include/playbook_included.yml
new file mode 100644
--- /dev/null
+++ b/test/playbook-include/playbook_included.yml
@@ -0,0 +1,9 @@
+---
+- hosts: localhost
+  connection: local
+  gather_facts: no
+  tasks:
+  - command: echo "no name"  # noqa 502
+  - name: Another task
+    debug:
+      msg: debug message
diff --git a/test/playbook-include/playbook_post.yml b/test/playbook-include/playbook_post.yml
new file mode 100644
--- /dev/null
+++ b/test/playbook-include/playbook_post.yml
@@ -0,0 +1,8 @@
+---
+- hosts: localhost
+  tasks:
+  - command: echo "no name"  # noqa 502
+  post_tasks:
+    - command: echo "no name"  # noqa 502
+    - name: Including another playbook
+      include: playbook_included.yml
diff --git a/test/playbook-include/playbook_pre.yml b/test/playbook-include/playbook_pre.yml
new file mode 100644
--- /dev/null
+++ b/test/playbook-include/playbook_pre.yml
@@ -0,0 +1,8 @@
+---
+- hosts: localhost
+  tasks:
+  - command: echo "no name"  # noqa 502
+  pre_tasks:
+    - command: echo "no name"  # noqa 502
+    - name: Including another playbook
+      include: playbook_included.yml