Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pre_tasks include playbook error #641

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ansiblelint/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions test/TestPretaskIncludePlaybook.py
Original file line number Diff line number Diff line change
@@ -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))
9 changes: 9 additions & 0 deletions test/playbook-include/playbook_included.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/playbook-include/playbook_post.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/playbook-include/playbook_pre.yml
Original file line number Diff line number Diff line change
@@ -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