在Ansible (1.9.4)或2.0.0中
我运行了以下操作:
- debug: msg="line1 \n {{ var2 }} \n line3 with var3 = {{ var3 }}"
猫$ roles/setup_jenkins_slave/tasks/main.yml
- debug: msg="Installing swarm slave = {{ slave_name }} at {{ slaves_dir }}/{{ slave_name }}"
tags:
- koba
- debug: msg="1 == Slave properties = fsroot[ {{ slave_fsroot }} ], master[ {{ slave_master }} ], connectingToMasterAs[ {{ slave_user }} ], description[ {{ slave_desc }} ], No.Of.Executors[ {{ slave_execs }} ], LABELs[ {{ slave_labels }} ], mode[ {{ slave_mode }} ]"
tags:
- koba
- debug: msg="print(2 == Slave properties = \n\nfsroot[ {{ slave_fsroot }} ],\n master[ {{ slave_master }} ],\n connectingToMasterAs[ {{ slave_user }} ],\n description[ {{ slave_desc }} ],\n No.Of.Executors[ {{ slave_execs }} ],\n LABELs[ {{ slave_labels }} ],\n mode[ {{ slave_mode }} ])"
tags:
- koba
但是这不是用新的行打印变量(对于第三个调试操作)?
发布于 2015-12-10 08:37:15
作为一种变通方法,我使用了with_items,它对我来说还不错。
- debug: msg="Installing swarm slave = {{ slave_name }} at {{ slaves_dir }}/{{ slave_name }}"
- debug: msg="Slave properties = {{ item.prop }} [ {{ item.value }} ]"
with_items:
- { prop: 'fsroot', value: "{{ slave_fsroot }}" }
- { prop: 'master', value: "{{ slave_master }}" }
- { prop: 'connectingToMasterAs', value: "{{ slave_user }}" }
- { prop: 'description', value: "{{ slave_desc }}" }
- { prop: 'No.Of.Executors', value: "{{ slave_execs }}" }
- { prop: 'LABELs', value: "{{ slave_labels }}" }
- { prop: 'mode', value: "{{ slave_mode }}" }
tags:
- koba
发布于 2016-12-28 14:01:41
debug模块支持数组,所以你可以这样做:
debug:
msg:
- "First line"
- "Second line"
输出:
ok: [node1] => {
"msg": [
"First line",
"Second line"
]
}
或者,您可以使用以下答案中的方法:
发布于 2016-10-30 11:43:25
我发现使用debug打印多行文本最方便的方法是:
- name: Print several lines of text
vars:
msg: |
This is the first line.
This is the second line with a variable like {{ inventory_hostname }}.
And here could be more...
debug:
msg: "{{ msg.split('\n') }}"
它将消息拆分为一个数组,debug将每一行打印为一个字符串。输出为:
ok: [example.com] => {
"msg": [
"This is the first line.",
"This is the second line with a variable like example.com",
"And here could be more...",
""
]
}
感谢jhutar。
https://stackoverflow.com/questions/34188167
复制相似问题