Skip to content

Commit

Permalink
Fix rule skipping in pre and post task include plays (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
awcrosby authored Dec 3, 2019
1 parent cd515a6 commit dec5b4f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
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

0 comments on commit dec5b4f

Please sign in to comment.