Ansible: Task executor use .format() which have problem with \u2018 characters

Created on 30 Dec 2016  ·  2Comments  ·  Source: ansible/ansible

ISSUE TYPE

  • Bug Report
COMPONENT NAME

ansible/plugins/action/__init__.py

ANSIBLE VERSION
ansible 2.2.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION

none

OS / ENVIRONMENT

x86_64 GNU/Linux

SUMMARY

An error coming back from a linux box contains the \u2018 character which seems to have an implementation issue in python 2.x.

see - '{0}'.format(u'Test it\u2018s unicode implementation')
Traceback (most recent call last):
File "", line 1, in
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 7: ordinal not in range(128)

but run fine in python 3.x

STEPS TO REPRODUCE

Message coming back from the linux box, \u2018 is used several times :
fatal: [crlg.be-cloud.be]: FAILED! => {
"failed": true,
"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of ‘/tmp/ansible-tmp-1483137683.83-3208985635661/’: Operation not permitted\nchown: changing ownership of ‘/tmp/ansible-tmp-1483137683.83-3208985635661/git.py’: Operation not permitted\n). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"
}

EXPECTED RESULTS

The message should be displayed

ACTUAL RESULTS
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 119, in run
    res = self._execute()
  File "/usr/lib/python2.7/dist-packages/ansible/executor/task_executor.py", line 490, in _execute
    result = self._handler.run(task_vars=variables)
  File "/usr/lib/python2.7/dist-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/dist-packages/ansible/plugins/action/__init__.py", line 618, in _execute_module
    self._fixup_perms2(remote_files, remote_user)
  File "/usr/lib/python2.7/dist-packages/ansible/plugins/action/__init__.py", line 395, in _fixup_perms2
    ' see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user'.format(res['rc'], res['stderr']))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 29: ordinal not in range(128)

fatal: [crlg.be-cloud.be]: FAILED! => {
    "failed": true, 
    "msg": "Unexpected failure during module execution.", 
    "stdout": ""
}

I fixed the problem using the "xxxx %s xxxx" % (res['rc'], res['stderr']) instead.

affects_2.2 bug python3

All 2 comments

I believe this was fixed in this commit to devel: bb5d8fb476c6e42f1e89b47c00e45f8b088ae40b and cherry-picked to the stable-2.2 branch here: 27be8a10222fbf7a7a4b51c642170e11f2823d39

It should make it into the next 2.2 release. If you'd care to test it out now to make sure you can checkout the stable-2.2 branch and try running from a checkout or you can download the ansible-2.2.1.0-0.2.rc2.tar.gz from here: https://releases.ansible.com/ansible/ to try it out.

I'll close this in a few days unless you report that it's still a problem with one of those. Thanks!

needs_info

I patched my install and this works for me.

Thanks !!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hryamzik picture hryamzik  ·  3Comments

greggilbert picture greggilbert  ·  3Comments

rokka-n picture rokka-n  ·  3Comments

cowboy picture cowboy  ·  3Comments

RaymiiOrg picture RaymiiOrg  ·  3Comments