Repository: ansible/ansible-lint

Issue:
False Positive ANSIBLE0014 does not allow command:args:stdin
# Issue Type
- Bug report

# Ansible and Ansible Lint details

```
ansible --version
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'$HOME/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Aug  2 2017, 11:05:32) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

ansible-lint --version
ansible-lint 3.4.17
```

- ansible installation method: OS package
- ansible-lint installation method: pip

# Desired Behaviour

The `stdin` argument to the `command` module should not trigger the "Environment variables don't work as part of command" error.

# Actual Behaviour (Bug report only)

The EnvVarsInCommandRule (ANSIBLE0014) linter rule rejects the following playbook:

```
- hosts: localhost
  tasks:
    - command: /bin/cat
      args:
        stdin: "Hello, world!"
```

due to the presence of the `stdin` attribute which was added in Ansible 2.4. This appears to be because `stdin` is missing from `expected_args`.


Discussion:

Resolving patch:
diff --git a/lib/ansiblelint/rules/EnvVarsInCommandRule.py b/lib/ansiblelint/rules/EnvVarsInCommandRule.py
--- a/lib/ansiblelint/rules/EnvVarsInCommandRule.py
+++ b/lib/ansiblelint/rules/EnvVarsInCommandRule.py
@@ -29,7 +29,7 @@ class EnvVarsInCommandRule(AnsibleLintRule):
                   'command through environment argument'
     tags = ['bug']
 
-    expected_args = ['chdir', 'creates', 'executable', 'removes', 'warn',
+    expected_args = ['chdir', 'creates', 'executable', 'removes', 'stdin', 'warn',
                      'cmd', '__ansible_module__', '__ansible_arguments__',
                      LINE_NUMBER_KEY, FILENAME_KEY]
 


Test patch:
diff --git a/test/TestEnvVarsInCommand.py b/test/TestEnvVarsInCommand.py
--- a/test/TestEnvVarsInCommand.py
+++ b/test/TestEnvVarsInCommand.py
@@ -1,6 +1,9 @@
 import unittest
+import ansible
+
 from ansiblelint import Runner, RulesCollection
 from ansiblelint.rules.EnvVarsInCommandRule import EnvVarsInCommandRule
+from pkg_resources import parse_version
 
 
 class TestEnvVarsInCommand(unittest.TestCase):
@@ -14,6 +17,12 @@ def test_file_positive(self):
         good_runner = Runner(self.collection, success, [], [], [])
         self.assertEqual([], good_runner.run())
 
+    @unittest.skipIf(parse_version(ansible.__version__) < parse_version('2.4'), "not supported with ansible < 2.4")
+    def test_file_positive_2_4(self):
+        success = 'test/env-vars-in-command-success_2_4_style.yml'
+        good_runner = Runner(self.collection, success, [], [], [])
+        self.assertEqual([], good_runner.run())
+
     def test_file_negative(self):
         failure = 'test/env-vars-in-command-failure.yml'
         bad_runner = Runner(self.collection, failure, [], [], [])
diff --git a/test/env-vars-in-command-success_2_4_style.yml b/test/env-vars-in-command-success_2_4_style.yml
new file mode 100644
--- /dev/null
+++ b/test/env-vars-in-command-success_2_4_style.yml
@@ -0,0 +1,7 @@
+- hosts: localhost
+
+  tasks:
+  - name: command with stdin (ansible > 2.4)
+    command: /bin/cat
+    args:
+      stdin: "Hello, world!"
\ No newline at end of file