问题描述
我在远程系统上获取命令的输出并将其存储在一个变量中.然后使用它来填充放置在系统上的文件模板.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!