summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Noseworthy <mike.noseworthy@gmail.com>2016-11-22 15:49:47 -0330
committerToshio Kuratomi <a.badger@gmail.com>2016-11-22 11:20:21 -0800
commit27be8a10222fbf7a7a4b51c642170e11f2823d39 (patch)
treef2cfac14c10f0ddd1106aa66dff41cac65d57964 /lib
parentf62224497eb527795a11a39808f5eb82671cf962 (diff)
downloadansible-27be8a10222fbf7a7a4b51c642170e11f2823d39.tar.gz
Fix unicode handling in fixup_perms2 errorhandling (#18565)
The _fixup_perms2 method checks to see if the user that is being sudo'd is an unprivileged user or root. If it is an unprivileged user, some checks are done to see if becoming this user would lock the ssh user out of temp files, among other things. If this check fails, an error prints telling the user to check the documentation for becoming an unprivileged user. On some systems, the stderr prints out the unprivileged user the ssh user was trying to become contained in smartquotes. These quotes aren't in the ASCII range, and so when we're trying to call `str.format()` to combine the stderr message with the error text we get a UnicodeEncodeError as python can't coerce the smartquotes using the system default encoding. By calling `to_native()` on the error message we can ensure that the error message is a native string for the `Exception` handling, as `Exception` messages need to be native strings to avoid errors (byte strings in python2, and text strings in python3) Fixes: #18444 (cherry picked from commit bb5d8fb476c6e42f1e89b47c00e45f8b088ae40b)
Diffstat (limited to 'lib')
-rw-r--r--lib/ansible/plugins/action/__init__.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index 9ab7d877c3..a08e113a05 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -374,7 +374,7 @@ class ActionBase(with_metaclass(ABCMeta, object)):
if execute:
res = self._remote_chmod(remote_paths, 'u+x')
if res['rc'] != 0:
- raise AnsibleError('Failed to set file mode on remote temporary files (rc: {0}, err: {1})'.format(res['rc'], res['stderr']))
+ raise AnsibleError('Failed to set file mode on remote temporary files (rc: {0}, err: {1})'.format(res['rc'], to_native(res['stderr'])))
res = self._remote_chown(remote_paths, self._play_context.become_user)
if res['rc'] != 0 and remote_user == 'root':
@@ -390,18 +390,18 @@ class ActionBase(with_metaclass(ABCMeta, object)):
' https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user')
res = self._remote_chmod(remote_paths, 'a+%s' % mode)
if res['rc'] != 0:
- raise AnsibleError('Failed to set file mode on remote files (rc: {0}, err: {1})'.format(res['rc'], res['stderr']))
+ raise AnsibleError('Failed to set file mode on remote files (rc: {0}, err: {1})'.format(res['rc'], to_native(res['stderr'])))
else:
raise AnsibleError('Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user'
' (rc: {0}, err: {1}). For information on working around this,'
- ' see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user'.format(res['rc'], res['stderr']))
+ ' see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user'.format(res['rc'], to_native(res['stderr'])))
elif execute:
# Can't depend on the file being transferred with execute
# permissions. Only need user perms because no become was
# used here
res = self._remote_chmod(remote_paths, 'u+x')
if res['rc'] != 0:
- raise AnsibleError('Failed to set file mode on remote files (rc: {0}, err: {1})'.format(res['rc'], res['stderr']))
+ raise AnsibleError('Failed to set file mode on remote files (rc: {0}, err: {1})'.format(res['rc'], to_native(res['stderr'])))
return remote_paths