# Removing unicode from output

**URL:** <https://forum.ansible.com/t/removing-unicode-from-output/37274>\
**Category:** Ansible Project\
**Created:** [October 27, 2022, 3:17pm UTC](https://forum.ansible.com/t/removing-unicode-from-output/37274 "2022-10-27T15:17:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 27, 2022, 3:17pm UTC](https://forum.ansible.com/t/removing-unicode-from-output/37274/1 "2022-10-27T15:17:58Z")

</div>

I was reading some suggestions on how to remove the u’ unicode presentation from my output, but none of them work. Here’s what I’m trying:

- name: Set List of user’s information  
set\_fact:  
user\_info: “{{ user\_show.results | json\_query(‘[\*].json.result.result.{uid: uid[0], email: mail[0], sn: sn[0], fullname: cn[0], givenName: givenname[0], telephonenumber: telephonenumber[0], homedir: homedirectory[0]}’) | list | to\_yaml }}”

- name: Prepare report  
template:  
src: files/users.csv.j2  
dest: /tmp/users.csv  
delegate\_to: localhost  
run\_once: true

In the template file, I’m trying to output the each entry as a new line in the CSV file:

sAMAccountName,sn,FullName,givenName,email,telephoneNumber,homedir  
{% for user in user\_info %}  
{{ user.uid,user.sn,user.fullname,user.givenName,user.email,user.telephonenumber,user.homedir }}  
{% endfor %}

If I do NOT use the to\_yaml (or to\_nice\_yaml) filter, I get the output I want, but with the u’ on each string. If I do use the filter on the variable above, I get a bunch of AnsibleUndefined as seen below:

With to\_yaml:  
sAMAccountName,sn,FullName,givenName,email,telephoneNumber,homedir  
(AnsibleUndefined, AnsibleUndefined, AnsibleUndefined, AnsibleUndefined, AnsibleUndefined, AnsibleUndefined, AnsibleUndefined)

Without to\_yaml:

sAMAccountName,sn,FullName,givenName,email,telephoneNumber,homedir  
(u’user1’, u’User1’, u’Test User1’, u’Test’, u’user1@example.com’, u’(609) xxx-yyyy’, u’/home/user1’)  
(u’user2’, u’User2’, u’Test User2’, u’Test’, u’user2@example.com’, u’(609) xxx-yyyy’, u’/home/user2’)

Any ideas?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 27, 2022, 3:39pm UTC](https://forum.ansible.com/t/removing-unicode-from-output/37274/2 "2022-10-27T15:39:43Z")

</div>

The problem here is that your template is creating a python tuple, and not creating a CSV of values

You likely want this instead:

{{ user.uid }},{{ [user.sn](http://user.sn) }},{{ user.fullname }},{{ user.givenName }},{{ user.email }},{{ user.telephonenumber }},{{ user.homedir }}

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 27, 2022, 3:48pm UTC](https://forum.ansible.com/t/removing-unicode-from-output/37274/3 "2022-10-27T15:48:39Z")

</div>

Thanks Matt! Worked like a charm. I knew I was overlooking something, just wasn’t sure what it was.

Thanks,  
Harry
