summaryrefslogtreecommitdiffstats
path: root/examples/playbooks/rule-risky-shell-pipe-pass.yml
blob: 386e8e812835bdcc6563920458ea8631642d3297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
- name: Test fixture for risky-shell-pipe
  hosts: localhost
  become: false
  tasks:
    - name: Pipeline with pipefail
      ansible.builtin.shell: set -o pipefail && false | cat
      changed_when: false

    - name: Pipeline with pipefail, multi-line
      ansible.builtin.shell: |
        set -o pipefail
        false | cat
      changed_when: false

    - name: Pipeline with pipefail, complex set
      ansible.builtin.shell: |
        set -e -x -o pipefail
        false | cat
      changed_when: false

    - name: Pipeline with pipefail, complex set
      ansible.builtin.shell: |
        set -e -x -o pipefail
        false | cat
      changed_when: false

    - name: Pipeline with pipefail, complex set
      ansible.builtin.shell: |
        set -eo pipefail
        false | cat
      changed_when: false

    - name: Pipeline with pipefail not at first line
      ansible.builtin.shell: |
        echo foo
        set -eo pipefail
        false | cat
      changed_when: false

    - name: Pipeline without pipefail, ignoring errors # noqa: risky-shell-pipe
      ansible.builtin.shell: false | cat
      failed_when: false
      changed_when: false

    - name: Non-pipeline without pipefail # noqa: command-instead-of-shell
      ansible.builtin.shell: "true"
      changed_when: false

    - name: Command without pipefail
      ansible.builtin.command: "true"
      changed_when: false

    - name: Shell with or
      ansible.builtin.shell: false || true
      changed_when: false

    - name: Another one
      ansible.builtin.shell: |
        set -o pipefail
        df | grep '/dev'
      changed_when: false

    - name: "PowerShell with pipefail should be ok, bug #3161"
      # https://github.com/ansible/ansible-lint/issues/3161
      ansible.builtin.shell:
        executable: /bin/pwsh
        cmd: |
          $ProgressPreference = 'this | that'
      changed_when: false