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

1,082 views
Skip to first unread message

Joel Sdc

unread,
May 12, 2014, 3:30:28 PM5/12/14
to ansible...@googlegroups.com
Hi, 

I'm having a little problem. When I run a simple playbook, on some servers I get a UnicodeEncodeError and the playbook is not executed.

I have the role "users_admin", it creates 3 groups, makes sure that 4 users exist and have a specific password and set a root password if it has changed.

root@cm:/etc/ansible/roles/users_admin# tree
.
└── tasks
    └── main.yml

1 directory, 1 file
root@cm:/etc/ansible/roles/users_admin# cat tasks/main.yml
---
- name: Global group 'admins'
  group: name=admins state=present gid=2000

- name: Global group 'support' 
  group: name=support state=present gid=2001

- name: Global group 'developers'
  group: name=developers state=present gid=2002

- name: Common 'admin' users
  user: name={{ item.name }} comment={{ item.gecos }} group=admins state=present uid={{ item.uid }} update_password=always password={{ item.passwd }} shell=/bin/bash
  with_items:
        - name: test1
          gecos: "test1"
          uid: 2050
          passwd: $6$2trU.wqo$c.QAHAngzhx.i6VwGM9zGoh8KdX3e.2EAnzYf3SDdIBWZFVo4OdHQjPxVl/8wmmD6hWYnxeyMF9rLAfNMk3oa0

        - name: test2
          gecos: "test2"
          uid: 2051
          passwd: $6$xIKLieVe$oFdw1N/FjdPQzdMGkViaG8UMTMwGhNBKvtVxMIbcDFTu3udXYtrH5un0Obmr6d9gDC66DK/dNfpP6jlESRtan/

        - name: test3
          gecos: "test3"
          uid: 2052
          passwd: $6$9bJs8kiu$lS.Jz.cGdx5J3s.Mw5V80GzO.U6tLLMwztuDZJsAe2JjpYLCedR96fAHbHVaozv0zRUrtexErdgTYQU0o0tCh0

        - name: test4
          gecos: "test4"
          uid: 2053
          passwd: $6$tmUQlubJ$0HI532QrAnlTGHwJlLEuGU2/uSAr42I2Y6aEFBbPlmXborYOlmVeCl5vI.YBLo3HDTFt/mx98HXv7yMqqgifa/

- name: Set root password
  user: name=root update_password=always password=$6$HqRU2uvR$6GV6CYTbtkxpbX7POk9FGglzK3M4G8icIuEWlxnllDe4FswqsQQbIaEsbT/JhaQe9ot4pAS8A/1RDurOb1e/p.

root@cm:/etc/ansible/roles/users_admin#

And this is the playbook:

root@cm:/etc/ansible/playbooks# cat test.yml
---
- name: Common settings
  hosts: all
  roles:
    - users_admin
root@cm:/etc/ansible/playbooks#

When I run the playbook, It fails in a newly installed Debian 7.5:

root@cm:/etc/ansible/playbooks# ansible-playbook test.yml

PLAY [Common settings] ********************************************************

GATHERING FACTS ***************************************************************
ok: [test]

TASK: [users_admin | Global group 'admins'] ***************
ok: [test]

TASK: [users_admin | Global group 'support'] **************
ok: [test]

TASK: [users_admin | Global group 'developers'] ***********
ok: [test]

TASK: [users_admin | Common 'admin' users] ****************
fatal: [test] => Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/ansible/runner/__init__.py", line 532, in _executor
    exec_rc = self._executor_internal(host, new_stdin)
  File "/usr/lib/pymodules/python2.7/ansible/runner/__init__.py", line 660, in _executor_internal
    complex_args=complex_args
  File "/usr/lib/pymodules/python2.7/ansible/runner/__init__.py", line 809, in _executor_internal_inner
    module_args = template.template(self.basedir, module_args, inject, fail_on_undefined=self.error_on_undefined_vars)
  File "/usr/lib/pymodules/python2.7/ansible/utils/template.py", line 321, in template
    varname = template_from_string(basedir, varname, vars, fail_on_undefined)
  File "/usr/lib/pymodules/python2.7/ansible/utils/template.py", line 543, in template_from_string
    data = data.decode('utf-8')
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 83: ordinal not in range(128)


FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/test.retry

test                       : ok=4    changed=0    unreachable=1    failed=0

root@cm:/etc/ansible/playbooks#


Output:

root@test:~# python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
>>>
root@test:~#

root@test:~# echo $LANG
en_US.UTF-8
root@test:~#

My Ansible version:

root@cm:/etc/ansible# ansible-playbook --version
ansible-playbook 1.5.5
root@cm:/etc/ansible#



Any idea what I'm doing wrong?

If it helps, this problem does NOT occur on every server, It could be something misconfigured on the client side as the same playbook works perfectly on other servers.

Thanks in advanced.

Best regards, 
Joel.





James Cammarata

unread,
May 12, 2014, 5:16:12 PM5/12/14
to ansible...@googlegroups.com
Can you try setting "module_lang = en_US.UTF-8" in your ansible.cfg to see if that corrects the issue?


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f7e9ae39-f234-4f09-a414-2cbaba9dc8a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joel Sdc

unread,
May 13, 2014, 7:41:25 AM5/13/14
to ansible...@googlegroups.com
Hi James, 

I have tried:

a) setting "module_lang = en_US.UTF-8" in ansible.cfg 
b) editing /usr/share/pyshared/ansible/constants.py and changing:

DEFAULT_MODULE_LANG       = get_config(p, DEFAULTS, 'module_lang',      'ANSIBLE_MODULE_LANG',      'C')

to

DEFAULT_MODULE_LANG       = get_config(p, DEFAULTS, 'module_lang',      'ANSIBLE_MODULE_LANG',      'en_US.UTF-8')


In both cases the problem persists. 

Any other ideas? 


thanks!!

James Cammarata

unread,
May 13, 2014, 8:33:27 AM5/13/14
to ansible...@googlegroups.com
Go ahead and open an issue on github for this, and we'll dig into it deeper. If setting the module_lang doesn't fix things, then the issue may not be on the client side.


Joel Sdc

unread,
May 14, 2014, 4:33:38 AM5/14/14
to ansible...@googlegroups.com
Hi James, 

Before opening an issue, I have tried after updating to latest ansible version available and the problem is solved.

Should I still open a specific issue for the version I was using prior to upgrade?

Thank you for your help.

Best regards, 
Joel.

Michael DeHaan

unread,
May 14, 2014, 8:24:17 AM5/14/14
to ansible...@googlegroups.com
No thank you, if it's already fixed we are good to go.

(For such reasons it's usually very useful to always indicate the ansible version when discussing a potential bug...)

Thanks!


Reply all
Reply to author
Forward
0 new messages