Convert Ansible variable from Unicode to ASCII


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.

The initiatorname.iscsi.template file contains:

When I run it however, I get a file with the following:

What I want:

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.


FWIW, if you really do have an array:

And you want your template/whatever result to be NOT:

But you prefer:

Then, this will do the trick:

(extra backslashes due to my code being in a string originally.)

Leave a Reply