Question:
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.
1 2 3 4 5 6 7 |
- 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:
1 2 |
InitiatorName={{ iscsiname.stdout_lines }} |
When I run it however, I get a file with the following:
1 2 |
InitiatorName=[u'iqn.2005-03.org.open-iscsi:2bb08ec8f94'] |
What I want:
1 2 |
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.
Answer:
FWIW, if you really do have an array:
1 2 |
[u'string1', u'string2', u'string3'] |
And you want your template/whatever result to be NOT:
1 2 |
ABC=[u'string1', u'string2', u'string3'] |
But you prefer:
1 2 |
ABC=["string1", "string2", "string3"] |
Then, this will do the trick:
1 2 |
ABC=["{{ iscsiname.stdout_lines | list | join("\", \"") }}"] |
(extra backslashes due to my code being in a string originally.)