将Ansible变量从Unicode转换为ASCII [英] 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.
- 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
initiatorname.iscsi.template文件包含:
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']
我想要什么:
InitiatorName=iqn.2005-03.org.open-iscsi:2bb08ec8f94
我在做什么错了?
我意识到我可以使用"echo"InitiatorName = $(/usr/sbin/iscsi-iname)">/etc/iscsi/initiatorname.iscsi将此文件写入文件,但这似乎是一种不可行的方法做到这一点.
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.
谢谢.
推荐答案
使用过滤器来避免unicode字符串:
Use a filter to avoid unicode strings:
InitiatorName = {{ iscsiname.stdout_lines | to_yaml }}
这篇关于将Ansible变量从Unicode转换为ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!