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

False positive EANSIBLE0014 also flags vars in shell task #275

Closed
queria opened this issue Jul 27, 2017 · 6 comments · Fixed by #477
Closed

False positive EANSIBLE0014 also flags vars in shell task #275

queria opened this issue Jul 27, 2017 · 6 comments · Fixed by #477
Milestone

Comments

@queria
Copy link

queria commented Jul 27, 2017

Issue Type

  • Bug report

Ansible and Ansible Lint details

ansible --version
ansible 2.3.0.0
ansible-lint --version
ansible-lint 3.4.13
  • ansible installation method: pip
  • ansible-lint installation method: pip

Desired Behaviour

EANSIBLE0014 should validate only command task, not shell.

Actual Behaviour (Bug report only)

When ansible-lint validating playbook with shell tasks with env vars

- hosts: "localhost"
  gather_facts: no
  become: no
  tasks:
      - shell: 'MYVAR="$(date)" env | grep MY'

it fails and complains about Env vars shouldn't be in command

test-play.yaml:5: [EANSIBLE0014] Environment variables don't work as part of command
@ssbarnea
Copy link
Member

What makes these bugs even worse is that there is no way to disable a specific check per command. ansible_skip_lint is like using shotgun for kill a fly as it disables all checks.

@babineaum
Copy link

What might be the status of this? I think i can put something into my ignore for this line but i would rather it be fixed...

@willthames
Copy link
Contributor

When I originally created EANSIBLE0014, I'm sure that using shell vars in the command didn't really work (maybe I have that wrong). Even now, I'm not hugely convinced by the use case - I prefer the use of environment. Ignoring the obvious ways to ansibilise the above command (I'll assume date is just an example), it could still be done with registering the results of a command and using that with environment in a subsequent command.

If you want to ignore issues with command or shell, you can just set the warn=no parameter - ansible-lint respects that (or at least it does for certain checks - that would be a different bug though if EANSIBLE0014 doesn't respect warn)

@hwoarang
Copy link

It seems that warn: no does not make ansible-lint ignore variable assignment on shell/command modules

- name: Test
  host: localhost
  gather_facts: False
  tasks:
    - name: A
      command: |
        a=10
      changed_when: false
      args:
        warn: no
[ANSIBLE0014] Environment variables don't work as part of command
test.yml:5
Task/Handler: A

The workaround for me is to actually put a comment as the first statement on shell/command modules. Then ansible-lint is happy

@ssbarnea
Copy link
Member

ssbarnea commented Dec 5, 2018

I am looking forward to see this fixed.

@awcrosby
Copy link
Contributor

awcrosby commented Feb 4, 2019

For consideration, I added PR #477 which would make this rule apply to only ‘command’ and not ‘shell’

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants