Why does Ansible fail to execute this simple shell script? <p>I came across a very strange problem with Ansible (1.8.2) that boils down to executing this simple command in a shell script:</p> <pre><code>#!/bin/sh # transform a String into lowercase chars: echo "TeSt" | tr [:upper:] [:lower:] </code></pre> <p>When I log into the remote Solaris machine, this script seems to work no matter in which shell I am (e.g., <code>/bin/sh</code>, <code>/bin/bash</code>):</p> <pre><code># ./test.sh test </code></pre> <p>Also when I execute this script using a remote ssh command, it works:</p> <pre><code># ssh root@&lt;remote-host&gt; '/tmp/test.sh' test </code></pre> <p>However, when I execute the same script with the Ansible <code>command</code> or <code>shell</code> modules, I get a "Bad String" error no matter what shell I specify:</p> <pre><code>- shell: executable=/bin/sh /tmp/test.sh [FATAL stderr: Bad string] - shell: executable=/bin/bash /tmp/test.sh [FATAL stderr: Bad string] - command: /tmp/test.sh [FATAL stderr: Bad string] </code></pre> <p>It took me ages to figure out that it works with the <code>raw</code> module:</p> <pre><code>- raw: executable=/bin/sh /tmp/test.sh [OK] </code></pre> <p>Does anyone have a clue why the <code>shell</code> and <code>command</code> modules produce this error?</p> <p>Some more info about the remote host on which the script fails:</p> <ul> <li>SunOS 5.10 Generic_150401-18 i86pc i386 i86pc</li> <li>All shells (<code>/bin/sh</code>, <code>/bin/bash</code>, <code>/bin/ksh</code>) are GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)</li> <li>Python 2.6.6</li> </ul> <p>The locale differs! When I log in or execute a remote ssh command, the locale looks like this:</p> <pre><code>LANG= LC_CTYPE="C" LC_NUMERIC="C" LC_TIME="C" LC_COLLATE="C" LC_MONETARY="C" LC_MESSAGES="C" LC_ALL= </code></pre> <p>However, with Ansible, I get this:</p> <pre><code>LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_ALL= </code></pre>