<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">exec_command (local)</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.1.0.0
  config file = /home/USER/git/ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.0.0
  config file = /home/USER/git/ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">We noticed that using a SUDO password with a non-ascii character causes Ansible to throw an exception when feeding the password to sudo. In my case the password include the ° character (0xb0), like the error output indicates:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not in range(128)"><pre class="notranslate"><code class="notranslate">UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not in range(128)
</code></pre></div>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">I intend to write a minimal reproducer an using the master branch.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[USER@SYSTEM ansible]$ ansible-playbook some_playbook.yml -K -vvv
Using /home/USER/git/ansible/ansible.cfg as config file
SUDO password:

PLAY [system01] ****************************************************************

TASK [fetch from system] *******************************************************
task path: /home/USER/git/ansible/some_playbook.yml:32
&lt;localhost&gt; ESTABLISH LOCAL CONNECTION FOR USER: USER
&lt;localhost&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p &quot;` echo /tmp/ansible-tmp-1476453804.28-165187216012413 `&quot; &amp;&amp; echo ansible-tmp-1476453804.28-165187216012413=&quot;` echo /tmp/ansible-tmp-1476453804.28-165187216012413 `&quot; ) &amp;&amp; sleep 0'
&lt;localhost&gt; PUT /tmp/tmpWVAqrj TO /tmp/ansible-tmp-1476453804.28-165187216012413/command
&lt;localhost&gt; EXEC /bin/sh -c 'chown -R sysauto /tmp/ansible-tmp-1476453804.28-165187216012413/ &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c 'setfacl -R -m u:sysauto:rX /tmp/ansible-tmp-1476453804.28-165187216012413/ &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c 'sudo -H -S  -p &quot;[sudo via ansible, key=opbxnljylhudewlchnsbwfnibhzyaent] password: &quot; -u sysauto /bin/sh -c '&quot;'&quot;'echo BECOME-SUCCESS-opbxnljylhudewlchnsbwfnibhzyaent; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1476453804.28-165187216012413/command'&quot;'&quot;' &amp;&amp; sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File &quot;/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py&quot;, line 124, in run
    res = self._execute()
  File &quot;/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py&quot;, line 446, in _execute
    result = self._handler.run(task_vars=variables)
  File &quot;/usr/lib/python2.7/site-packages/ansible/plugins/action/normal.py&quot;, line 33, in run
    results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
  File &quot;/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py&quot;, line 644, in _execute_module
    res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
  File &quot;/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py&quot;, line 718, in _low_level_execute_command
    rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
  File &quot;/usr/lib/python2.7/site-packages/ansible/plugins/connection/local.py&quot;, line 109, in exec_command
    p.stdin.write(self._play_context.become_pass + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not in range(128)

fatal: [system01]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;Unexpected failure during module execution.&quot;, &quot;stdout&quot;: &quot;&quot;}

NO MORE HOSTS LEFT *************************************************************

PLAY RECAP *********************************************************************
system01                   : ok=0    changed=0    unreachable=0    failed="><pre class="notranslate"><code class="notranslate">[USER@SYSTEM ansible]$ ansible-playbook some_playbook.yml -K -vvv
Using /home/USER/git/ansible/ansible.cfg as config file
SUDO password:

PLAY [system01] ****************************************************************

TASK [fetch from system] *******************************************************
task path: /home/USER/git/ansible/some_playbook.yml:32
&lt;localhost&gt; ESTABLISH LOCAL CONNECTION FOR USER: USER
&lt;localhost&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /tmp/ansible-tmp-1476453804.28-165187216012413 `" &amp;&amp; echo ansible-tmp-1476453804.28-165187216012413="` echo /tmp/ansible-tmp-1476453804.28-165187216012413 `" ) &amp;&amp; sleep 0'
&lt;localhost&gt; PUT /tmp/tmpWVAqrj TO /tmp/ansible-tmp-1476453804.28-165187216012413/command
&lt;localhost&gt; EXEC /bin/sh -c 'chown -R sysauto /tmp/ansible-tmp-1476453804.28-165187216012413/ &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c 'setfacl -R -m u:sysauto:rX /tmp/ansible-tmp-1476453804.28-165187216012413/ &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c 'sudo -H -S  -p "[sudo via ansible, key=opbxnljylhudewlchnsbwfnibhzyaent] password: " -u sysauto /bin/sh -c '"'"'echo BECOME-SUCCESS-opbxnljylhudewlchnsbwfnibhzyaent; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible-tmp-1476453804.28-165187216012413/command'"'"' &amp;&amp; sleep 0'
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 124, in run
    res = self._execute()
  File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 446, in _execute
    result = self._handler.run(task_vars=variables)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/action/normal.py", line 33, in run
    results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
  File "/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 644, in _execute_module
    res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 718, in _low_level_execute_command
    rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
  File "/usr/lib/python2.7/site-packages/ansible/plugins/connection/local.py", line 109, in exec_command
    p.stdin.write(self._play_context.become_pass + '\n')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not in range(128)

fatal: [system01]: FAILED! =&gt; {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

NO MORE HOSTS LEFT *************************************************************

PLAY RECAP *********************************************************************
system01                   : ok=0    changed=0    unreachable=0    failed=
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">Ansible is installed from Github:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.2.0 (devel 46a97e1f55) last updated 2016/06/30 21:16:46 (GMT +100)
  lib/ansible/modules/core: (detached HEAD 1d0d5db97a) last updated 2016/06/30 21:16:54 (GMT +100)
  lib/ansible/modules/extras: (detached HEAD 00b8b96906) last updated 2016/06/30 21:16:54 (GMT +100)
  config file = .../jonblog-build/app/ansible.cfg [removed unimportant path info]
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.2.0 (devel 46a97e1f55) last updated 2016/06/30 21:16:46 (GMT +100)
  lib/ansible/modules/core: (detached HEAD 1d0d5db97a) last updated 2016/06/30 21:16:54 (GMT +100)
  lib/ansible/modules/extras: (detached HEAD 00b8b96906) last updated 2016/06/30 21:16:54 (GMT +100)
  config file = .../jonblog-build/app/ansible.cfg [removed unimportant path info]
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cat ansible.cfg 
[defaults]
transport=paramiko"><pre class="notranslate"><code class="notranslate">cat ansible.cfg 
[defaults]
transport=paramiko
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Ubuntu 14.04<br>
Python 2.7.6</p>
<p dir="auto">Paramiko from <code class="notranslate">apt-get</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="apt-cache show python-paramiko
Package: python-paramiko
Priority: optional
Section: python
Installed-Size: 541
Maintainer: Ubuntu Developers &lt;ubuntu-devel-discuss@lists.ubuntu.com&gt;
Original-Maintainer: Jeremy T. Bouse &lt;jbouse@debian.org&gt;
Architecture: all
Source: paramiko
Version: 1.10.1-1git1build1
Provides: python2.7-paramiko
Depends: python (&gt;= 2.7), python (&lt;&lt; 2.8), python:any (&gt;= 2.7.1-0ubuntu2), python-crypto (&gt;= 2.1.0-2)
Filename: pool/main/p/paramiko/python-paramiko_1.10.1-1git1build1_all.deb
Size: 105776
MD5sum: e728ed22af7bead915a5e509140971bb
SHA1: 92f20ae140eeceb36d456bb696b4a5e5c7f36585
SHA256: b665fdc994b7d1944bc54aab781f9110d2e1e6e4d33257151bf6d2f8a2f56a7c
Description-en: Make ssh v2 connections with Python (Python 2)
 This is a library for making SSH2 connections (client or server).
 Emphasis is on using SSH2 as an alternative to SSL for making secure
 connections between Python scripts.  All major ciphers and hash methods
 are supported.  SFTP client and server mode are both supported too.
 .
 This is the Python 2 version of the package.
Description-md5: ef19708cf575fb15646b6a0f32043a47
Homepage: https://github.com/paramiko/paramiko/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: edubuntu-desktop-gnome"><pre class="notranslate"><code class="notranslate">apt-cache show python-paramiko
Package: python-paramiko
Priority: optional
Section: python
Installed-Size: 541
Maintainer: Ubuntu Developers &lt;ubuntu-devel-discuss@lists.ubuntu.com&gt;
Original-Maintainer: Jeremy T. Bouse &lt;jbouse@debian.org&gt;
Architecture: all
Source: paramiko
Version: 1.10.1-1git1build1
Provides: python2.7-paramiko
Depends: python (&gt;= 2.7), python (&lt;&lt; 2.8), python:any (&gt;= 2.7.1-0ubuntu2), python-crypto (&gt;= 2.1.0-2)
Filename: pool/main/p/paramiko/python-paramiko_1.10.1-1git1build1_all.deb
Size: 105776
MD5sum: e728ed22af7bead915a5e509140971bb
SHA1: 92f20ae140eeceb36d456bb696b4a5e5c7f36585
SHA256: b665fdc994b7d1944bc54aab781f9110d2e1e6e4d33257151bf6d2f8a2f56a7c
Description-en: Make ssh v2 connections with Python (Python 2)
 This is a library for making SSH2 connections (client or server).
 Emphasis is on using SSH2 as an alternative to SSL for making secure
 connections between Python scripts.  All major ciphers and hash methods
 are supported.  SFTP client and server mode are both supported too.
 .
 This is the Python 2 version of the package.
Description-md5: ef19708cf575fb15646b6a0f32043a47
Homepage: https://github.com/paramiko/paramiko/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu
Supported: 5y
Task: edubuntu-desktop-gnome
</code></pre></div>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">Using Paramiko as an SSH transport layer, with a <code class="notranslate">-K</code> root password containing a <code class="notranslate">£</code> pound sign causes a Python crash in Paramiko.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">I call my playbook with <code class="notranslate">ansible-playbook -K ansible/fetch-database.yml</code>. More details <a href="https://stackoverflow.com/questions/38132270/do-i-need-to-explicitly-switch-paramiko-or-ansible-to-use-utf-8-to-handle-non-as" rel="nofollow">in this post</a>.</p>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">I expected the playbook to execute without errors or crashes. The password is correct, and using the default SSH transport, it seems to work fine. (I had originally swapped to Paramiko as the default transport was hanging upon successful <code class="notranslate">su</code>, but a pull on the Ansible repo fixed that, so I have swapped back).</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">Upon encountering the <code class="notranslate">su</code> code, I get this crash inside Paramiko:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/executor/task_executor.py&quot;, line 96, in run
    item_results = self._run_loop(items)
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/executor/task_executor.py&quot;, line 252, in _run_loop
    res = self._execute(variables=task_vars)
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/executor/task_executor.py&quot;, line 447, in _execute
    result = self._handler.run(task_vars=variables)
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/action/normal.py&quot;, line 33, in run
    results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/action/__init__.py&quot;, line 647, in _execute_module
    res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/action/__init__.py&quot;, line 721, in _low_level_execute_command
    rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
  File &quot;/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/connection/paramiko_ssh.py&quot;, line 311, in exec_command
    chan.sendall(self._play_context.become_pass + '\n')
  File &quot;/usr/lib/python2.7/dist-packages/paramiko/channel.py&quot;, line 797, in sendall
    sent = self.send(s)
  File &quot;/usr/lib/python2.7/dist-packages/paramiko/channel.py&quot;, line 729, in send
    m.add_string(s[:size])
  File &quot;/usr/lib/python2.7/dist-packages/paramiko/message.py&quot;, line 259, in add_string
    self.packet.write(s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 1: ordinal not in range(128)

fatal: [server.example.com]: FAILED! =&gt; {&quot;failed&quot;: true, &quot;msg&quot;: &quot;Unexpected failure during module execution.&quot;, &quot;stdout&quot;: &quot;&quot;}"><pre class="notranslate"><code class="notranslate">An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/executor/task_executor.py", line 96, in run
    item_results = self._run_loop(items)
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/executor/task_executor.py", line 252, in _run_loop
    res = self._execute(variables=task_vars)
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/executor/task_executor.py", line 447, in _execute
    result = self._handler.run(task_vars=variables)
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/action/normal.py", line 33, in run
    results = merge_hash(results, self._execute_module(tmp=tmp, task_vars=task_vars))
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/action/__init__.py", line 647, in _execute_module
    res = self._low_level_execute_command(cmd, sudoable=sudoable, in_data=in_data)
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/action/__init__.py", line 721, in _low_level_execute_command
    rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
  File "/home/jon/Development/Personal/server-build/ansible/lib/ansible/plugins/connection/paramiko_ssh.py", line 311, in exec_command
    chan.sendall(self._play_context.become_pass + '\n')
  File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 797, in sendall
    sent = self.send(s)
  File "/usr/lib/python2.7/dist-packages/paramiko/channel.py", line 729, in send
    m.add_string(s[:size])
  File "/usr/lib/python2.7/dist-packages/paramiko/message.py", line 259, in add_string
    self.packet.write(s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 1: ordinal not in range(128)

fatal: [server.example.com]: FAILED! =&gt; {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
</code></pre></div>
<p dir="auto">It is possible that this would be solved with a bleeding-edge install of Paramiko. If you'd like me to install that in order to try it, please let me know how to do that - I'm just using the version in Ubuntu at the moment.</p>