Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

exec_command (local)

ANSIBLE VERSION

ansible 2.1.0.0
config file = /home/USER/git/ansible/ansible.cfg
configured module search path = Default w/o overrides

SUMMARY

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:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xb0' in position 0: ordinal not in range(128)

STEPS TO REPRODUCE

I intend to write a minimal reproducer an using the master branch.

ACTUAL RESULTS

[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
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: USER
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible-tmp-1476453804.28-165187216012413 `" && echo ansible-tmp-1476453804.28-165187216012413="` echo /tmp/ansible-tmp-1476453804.28-165187216012413 `" ) && sleep 0'
<localhost> PUT /tmp/tmpWVAqrj TO /tmp/ansible-tmp-1476453804.28-165187216012413/command
<localhost> EXEC /bin/sh -c 'chown -R sysauto /tmp/ansible-tmp-1476453804.28-165187216012413/ && sleep 0'
<localhost> EXEC /bin/sh -c 'setfacl -R -m u:sysauto:rX /tmp/ansible-tmp-1476453804.28-165187216012413/ && sleep 0'
<localhost> 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'"'"' && 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! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

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

PLAY RECAP *********************************************************************
system01 : ok=0 changed=0 unreachable=0 failed=

Issue 2:
ISSUE TYPE

Bug Report

ANSIBLE VERSION

Ansible is installed from Github:

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

CONFIGURATION

cat ansible.cfg
[defaults]
transport=paramiko

OS / ENVIRONMENT

Ubuntu 14.04

Python 2.7.6

Paramiko from apt-get:

apt-cache show python-paramiko
Package: python-paramiko
Priority: optional
Section: python
Installed-Size: 541
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Jeremy T. Bouse <jbouse@debian.org>
Architecture: all
Source: paramiko
Version: 1.10.1-1git1build1
Provides: python2.7-paramiko
Depends: python (>= 2.7), python (<< 2.8), python:any (>= 2.7.1-0ubuntu2), python-crypto (>= 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

SUMMARY

Using Paramiko as an SSH transport layer, with a -K root password containing a £ pound sign causes a Python crash in Paramiko.

STEPS TO REPRODUCE

I call my playbook with ansible-playbook -K ansible/fetch-database.yml. More details in this post.

EXPECTED RESULTS

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 su, but a pull on the Ansible repo fixed that, so I have swapped back).

ACTUAL RESULTS

Upon encountering the su code, I get this crash inside Paramiko:

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! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

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.