Skip to content

Commit

Permalink
Remove exceptions from unnamed-task rule (#1413)
Browse files Browse the repository at this point in the history
Closes: #1411
Signed-off-by: Thomas Sjögren <[email protected]>
  • Loading branch information
konstruktoid authored Feb 27, 2021
1 parent ed24aa6 commit 9d74f77
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 21 deletions.
5 changes: 3 additions & 2 deletions examples/playbooks/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
-
3 changes: 3 additions & 0 deletions examples/playbooks/task-has-name-failure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
- command: echo "no name"
- name:
command: echo "empty name"
- debug:
msg: "Debug without a name"
- meta: flush_handlers
7 changes: 4 additions & 3 deletions examples/playbooks/task-has-name-success.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 1 addition & 13 deletions src/ansiblelint/rules/TaskHasNameRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
4 changes: 2 additions & 2 deletions test/TestExamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/TestTaskHasName.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

0 comments on commit 9d74f77

Please sign in to comment.