# Bug in shell module? Wrong syntax not noticed

**URL:** <https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633>\
**Category:** Ansible Project\
**Created:** [June 1, 2016, 12:40pm UTC](https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633 "2016-06-01T12:40:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 1, 2016, 12:40pm UTC](https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633/1 "2016-06-01T12:40:20Z")

</div>

Dear all,

I stumbled upon this code, because it was not idempotent and reported  
as changed each time I ran the playbook:

- name: "copy file"  
&nbsp;&nbsp;shell: "cp /some/path/to/a/file.txt /home/foobar/some/other/path"  
&nbsp;&nbsp;args:  
&nbsp;&nbsp;&nbsp;&nbsp;creates="/home/foobar/some/other/path/file.txt"

Somehow I had missed that the creates argument is to be given with a  
colon, not with an equal sign. When using a colon, this task is  
idempotent.

Should this syntax error not be detected somehow? Or is this (by  
coincidence) valid YAML? The shell module does not respect the setting  
with an equal sign, only with a colon.

Johannes

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 1, 2016, 10:35pm UTC](https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633/2 "2016-06-01T22:35:47Z")

</div>

​the problem is you are mixing syntax:

this is valid:

​- name: “copy file”  
shell: “cp /some/path/to/a/file.txt /home/foobar/some/other/path creates=”/home/foobar/some/other/path/file.txt"

this is also valid:

- name: “copy file”  
shell: “cp /some/path/to/a/file.txt /home/foobar/some/other/path”  
args:  
creates: “/home/foobar/some/other/path/file.txt”

args won’t give you an error in the case you showed as you passed a string to the shell module which allows for arbitrary strings (shell commands). To the shell that would have appeared as setting a variable inline or an extra parameter.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 2, 2016, 7:25am UTC](https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633/3 "2016-06-02T07:25:19Z")

</div>

But I would have thought that as soon as an 'args:' appears, the shell  
module should get that the following is syntax-with-colon and throw an  
error otherwise.

Or do you mean that creates=foo could be a valid argument? But all  
arguments to the shell module should declare something (a=b), not just  
switch something on or off (disable\_foo).

Johannes

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [June 2, 2016, 4:54pm UTC](https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633/4 "2016-06-02T16:54:00Z")

</div>

modules don’t read args, ansible does, then passes them to the module, since the shell module is ‘free form’ there is really nothing to validate against, since what you are passing can work in a shell … there is no error thrown either.

---

<div class="post-metadata">

**Author:** ![Johannes\_Kastl](https://avatars.discourse-cdn.com/v4/letter/j/bbe5ce/32.png) [@Johannes\_Kastl](https://forum.ansible.com/u/Johannes_Kastl)\
**Post date:** [June 2, 2016, 5:36pm UTC](https://forum.ansible.com/t/bug-in-shell-module-wrong-syntax-not-noticed/21633/5 "2016-06-02T17:36:13Z")

</div>

I'll reword my thought:

If ansible is doing the parsing, it already distinguishes between the  
two syntax methods (the one with one line and all stuff and the other  
one where there is a line containing 'args:' and some more lines).

IMHO it should note that as soon as the 'args:' appears, everything  
after that should be in declarative syntax (foo: bar) and every line  
not containing a colon is wrong syntax.

Johannes
