Convert Ansible variable from Unicode to ASCII
ansible, unicode
Solution
FWIW, if you really do have an array:
[u'string1', u'string2', u'string3']
And you want your template/whatever result to be NOT:
ABC=[u'string1', u'string2', u'string3']
But you prefer:
ABC=["string1", "string2", "string3"]
Then, this will do the trick:
ABC=["{{ iscsiname.stdout_lines | list | join("\", \"") }}"]
(extra backslashes due to my code being in a string originally.)
Problem
I'm getting the output of a command on the remote system and storing it in a variable. It is then used to fill in a file template which gets placed on the system. ``` - name: Retrieve Initiator Name command: /usr/sbin/iscsi-iname register: iscsiname - name: Setup InitiatorName File template: src=initiatorname.iscsi.template dest=/etc/iscsi/initiatorname.iscsi ``` The initiatorname.iscsi.template file contains: ``` InitiatorName={{ iscsiname.stdout_lines }} ``` When I run it however, I get a file with the following: ``` InitiatorName=[u'iqn.2005-03.org.open-iscsi:2bb08ec8f94'] ``` What I want: ``` InitiatorName=iqn.2005-03.org.open-iscsi:2bb08ec8f94 ``` What am I doing wrong? I realize I could write this to the file with an "echo "InitiatorName=$(/usr/sbin/iscsi-iname)" > /etc/iscsi/initiatorname.iscsi" but that seems like an un-Ansible way of doing it. Thanks in advance.