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

risky-shell-pipe false positive: pipe operator in multi-line Jinja template is interpreted as shell pipe #3879

Open
lucendio opened this issue Nov 2, 2023 · 1 comment
Labels

Comments

@lucendio
Copy link

lucendio commented Nov 2, 2023

Summary

Using Jinja template with operator | in multi-line (!) shell cmd string is recognized as risky-shell-pipe violation.

Issue Type
  • Bug Report
OS / ENVIRONMENT
ansible-lint --version
ansible-lint 6.21.1 using ansible-core:2.14.11 ansible-compat:4.1.10 ruamel-yaml:0.17.40 ruamel-yaml-clib:0.2.8
Actual / Desired Behavior
- vars:
    values:
      - 'itemA'
      - 'itemB'
  ansible.builtin.shell:
    executable: '/usr/bin/bash'
    cmd: >-
      echo {{
        values | first
      }}

fails while it's not supposed to:

risky-shell-pipe: Shells that use pipes should set the pipefail option.
tasks/example.yaml:1 Task/Handler: shell executable=/usr/bin/bash cmd=echo {{
  values | first
}}

BUT

- vars:
    values:
      - 'itemA'
      - 'itemB'
  ansible.builtin.shell:
    executable: '/usr/bin/bash'
    cmd: >-
      set -o pipefail;
      echo {{
        values | first
      }}

and

- vars:
    values:
      - 'itemA'
      - 'itemB'
  ansible.builtin.shell:
    executable: '/usr/bin/bash'
    cmd: >-
      echo {{ values | first }}

succeed.

While the result of the last 2 examples is expected, the first one is not. If pipe operators are only part of a Jinja template in the cmd string value the rule should not match regardless whether it's multi-line or single-line.

@lucendio lucendio added bug new Triage required labels Nov 2, 2023
@ssbarnea ssbarnea removed the new Triage required label Nov 3, 2023
@ssbarnea
Copy link
Member

ssbarnea commented Nov 3, 2023

A PR to improve the behaviour would be more than welcomed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

2 participants