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

Remove exceptions from unnamed-task rule #1413

Merged
merged 1 commit into from
Feb 27, 2021
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
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))