yaml文件输出的|与>的区别
主要区别:
使用 | 会保留换行符 \n,在输出的时候转化的\n
使用 > 则不会在换行的时候输出换行,而是替换为空格
示例
[student@workstation wangxc]$ cat playbook-test.yaml
---
- name: Configure important user consistently
hosts:
- test
tasks:
- name: first debug test
debug:
msg: |
使用|会保留换行符
使用|会保留换行符
使用|会保留换行符
- name: second debug test
debug:
msg: >
使用>会把换行符转化为空格
使用>会把换行符转化为空格
使用>会把换行符转化为空格
输出结果
[student@workstation wangxc]$ ansible-playbook playbook-test.yaml
PLAY [Configure important user consistently] *****************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************
ok: [servera.lab.example.com]
TASK [first debug test] **************************************************************************************************************
ok: [servera.lab.example.com] => {
"msg": "使用|会保留换行符\n使用|会保留换行符\n使用|会保留换行符\n"
}
TASK [second debug test] *************************************************************************************************************
ok: [servera.lab.example.com] => {
"msg": "使用>会把换行符转化为空格 使用>会把换行符转化为空格 使用>会把换行符转化为空格\n"
}
PLAY RECAP ***************************************************************************************************************************
servera.lab.example.com : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
可以通过结果看到根本的区别:
- 使用|会保留换行符\n使用|会保留换行符\n使用|会保留换行符\n
- 使用>会把换行符转化为空格 使用>会把换行符转化为空格 使用>会把换行符转化为空格\n