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?