File tree Expand file tree Collapse file tree 4 files changed +24
-7
lines changed Expand file tree Collapse file tree 4 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,7 @@ prerun
255
255
prettierignore
256
256
programoutput
257
257
psutil
258
+ pwsh
258
259
pyargs
259
260
pycache
260
261
pycharm
Original file line number Diff line number Diff line change 60
60
set -o pipefail
61
61
df | grep '/dev'
62
62
changed_when : false
63
+
64
+ - name : " PowerShell with pipefail should be ok, bug #3161"
65
+ # https://github.com/ansible/ansible-lint/issues/3161
66
+ ansible.builtin.shell :
67
+ executable : /bin/pwsh
68
+ cmd : |
69
+ $ProgressPreference = 'this | that'
70
+ changed_when : false
Original file line number Diff line number Diff line change 2
2
3
3
This rule checks for the bash ` pipefail ` option with the Ansible ` shell ` module.
4
4
5
- You should always set ` pipefail ` when piping output from a command to another.
6
- The return status of a pipeline is the exit status of the command.
7
- The ` pipefail ` option ensures that tasks fail as expected if the first command fails.
5
+ You should always set ` pipefail ` when piping output from one command to another.
6
+ The return status of a pipeline is the exit status of the command. The
7
+ ` pipefail ` option ensures that tasks fail as expected if the first command
8
+ fails.
9
+
10
+ As this requirement does apply to PowerShell, for shell commands that have
11
+ ` pwsh ` inside ` executable ` attribute, this rule will not trigger.
8
12
9
13
## Problematic Code
10
14
@@ -14,7 +18,7 @@ The `pipefail` option ensures that tasks fail as expected if the first command f
14
18
hosts : localhost
15
19
tasks :
16
20
- name : Pipeline without pipefail
17
- shell : false | cat
21
+ ansible.builtin. shell : false | cat
18
22
` ` `
19
23
20
24
## Correct Code
@@ -23,13 +27,13 @@ The `pipefail` option ensures that tasks fail as expected if the first command f
23
27
---
24
28
- name : Example playbook
25
29
hosts : localhost
26
- become : no
30
+ become : false
27
31
tasks :
28
32
- name : Pipeline with pipefail
29
- shell : set -o pipefail && false | cat
33
+ ansible.builtin. shell : set -o pipefail && false | cat
30
34
31
35
- name : Pipeline with pipefail, multi-line
32
- shell : |
36
+ ansible.builtin. shell : |
33
37
set -o pipefail # <-- adding this will prevent surprises
34
38
false | cat
35
39
` ` `
Original file line number Diff line number Diff line change @@ -45,6 +45,10 @@ def matchtask(
45
45
46
46
jinja_stripped_cmd = self .unjinja (get_cmd_args (task ))
47
47
48
+ # https://github.com/ansible/ansible-lint/issues/3161
49
+ if "pwsh" in task ["action" ].get ("executable" , "" ):
50
+ return False
51
+
48
52
return bool (
49
53
self ._pipe_re .search (jinja_stripped_cmd )
50
54
and not self ._pipefail_re .search (jinja_stripped_cmd )
You can’t perform that action at this time.
0 commit comments