Skip to content

Commit

Permalink
Improve risky-shell-pipe rule matching (#1453)
Browse files Browse the repository at this point in the history
Removes one false positive case where user set ignore_errors: true,
case in which the rule does not make much sense.

Fixes: #1250
  • Loading branch information
ssbarnea committed Mar 10, 2021
1 parent 857626b commit 1be1871
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ansiblelint/rules/ShellWithoutPipefail.py
Expand Up @@ -2,6 +2,7 @@
from typing import Any, Dict, Union

from ansiblelint.rules import AnsibleLintRule
from ansiblelint.utils import convert_to_boolean


class ShellWithoutPipefail(AnsibleLintRule):
Expand Down Expand Up @@ -39,4 +40,5 @@ def matchtask(self, task: Dict[str, Any]) -> Union[bool, str]:
return bool(
self._pipe_re.search(unjinjad_cmd)
and not self._pipefail_re.match(unjinjad_cmd)
and not convert_to_boolean(task['action'].get('ignore_errors', False))
)
4 changes: 4 additions & 0 deletions test/TestShellWithoutPipefail.py
Expand Up @@ -65,6 +65,10 @@
- shell: |
set -o pipefail
df | grep '/dev'
- name: should not fail due to ignore_errors being true
shell: false | cat
ignore_errors: true
'''


Expand Down

0 comments on commit 1be1871

Please sign in to comment.