diff --git a/examples/playbooks/example.yml b/examples/playbooks/example.yml index abe00db0a4..8c264180b4 100644 --- a/examples/playbooks/example.yml +++ b/examples/playbooks/example.yml @@ -32,17 +32,18 @@ - name: passing git as an argument to another task action: debug msg="{{item}}" - with_items: + with_items: - git # yamllint wrong indentation - bobbins - name: yum latest yum: state=latest name=httpd - - debug: msg="task without a name" + - debug: msg="debug task without a name" - name: apt latest apt: state=latest name=apache2 + - meta: flush_handlers # empty task is currently accepted by ansible as valid code: - diff --git a/examples/playbooks/task-has-name-failure.yml b/examples/playbooks/task-has-name-failure.yml index ce947f336b..26756c02ee 100644 --- a/examples/playbooks/task-has-name-failure.yml +++ b/examples/playbooks/task-has-name-failure.yml @@ -5,3 +5,6 @@ - command: echo "no name" - name: command: echo "empty name" + - debug: + msg: "Debug without a name" + - meta: flush_handlers diff --git a/examples/playbooks/task-has-name-success.yml b/examples/playbooks/task-has-name-success.yml index b708f5a786..6e946c2706 100644 --- a/examples/playbooks/task-has-name-success.yml +++ b/examples/playbooks/task-has-name-success.yml @@ -4,6 +4,7 @@ tasks: - name: This task has a name command: echo "Hello World" - - debug: - msg: "Hello World" - - meta: flush_handlers + - name: Debug task with name + debug: msg="Hello World" + - name: Flush handler with name + meta: flush_handlers diff --git a/src/ansiblelint/rules/TaskHasNameRule.py b/src/ansiblelint/rules/TaskHasNameRule.py index 02635933cc..a26a76d41a 100644 --- a/src/ansiblelint/rules/TaskHasNameRule.py +++ b/src/ansiblelint/rules/TaskHasNameRule.py @@ -34,17 +34,5 @@ class TaskHasNameRule(AnsibleLintRule): tags = ['idiom'] version_added = 'historic' - _nameless_tasks = [ - 'meta', - 'debug', - 'include_role', - 'import_role', - 'include_tasks', - 'import_tasks', - ] - def matchtask(self, task: Dict[str, Any]) -> Union[bool, str]: - return ( - not task.get('name') - and task["action"]["__ansible_module__"] not in self._nameless_tasks - ) + return not task.get('name') diff --git a/test/TestExamples.py b/test/TestExamples.py index 18cb0dbdfb..0961e29e1e 100644 --- a/test/TestExamples.py +++ b/test/TestExamples.py @@ -15,9 +15,9 @@ def _change_into_examples_dir(request): @pytest.mark.usefixtures('_change_into_examples_dir') def test_example(default_rules_collection): - """example.yml is expected to have 15 match errors inside.""" + """example.yml is expected to have 16 match errors inside.""" result = Runner('playbooks/example.yml', rules=default_rules_collection).run() - assert len(result) == 15 + assert len(result) == 16 @pytest.mark.parametrize( diff --git a/test/TestTaskHasName.py b/test/TestTaskHasName.py index 3b72e5f3fc..0aa0d0d60f 100644 --- a/test/TestTaskHasName.py +++ b/test/TestTaskHasName.py @@ -21,4 +21,4 @@ def test_file_negative(self): failure = 'examples/playbooks/task-has-name-failure.yml' bad_runner = Runner(failure, rules=self.collection) errs = bad_runner.run() - self.assertEqual(2, len(errs)) + self.assertEqual(4, len(errs))