linux学习

Playbook中 “|” 与 “>”的区别

“|”和“>”的区别:“|”保留换行符,“>”把多行合并为一行。

举例如下:

通过copy模块创建/tmp/1.txt,文件中有两行内容,分别是Hello World和sha sha dan,代码示意如下:

[root@pubserver ansible]# vim shu.yml
---
- name: shu file
  hosts: webservers
  tasks:
    - name: mkfile 1.txt
      copy:
        dest: /tmp/1.txt
        content: |
          Hello Word!
          sha sha dan.
[root@pubserver ansible]# ansible-playbook shu.yml

PLAY [shu file] ***********************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
ok: [web1]
ok: [web2]

TASK [mkfile 1.txt] *******************************************************************************************************************************
changed: [web1]
changed: [web2]

PLAY RECAP ****************************************************************************************************************************************
web1                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
web2                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0 
[root@web1 tmp]# cat /tmp/1.txt
Hello Word!
sha sha dan.

通过copy模块创建/tmp/2.txt,文件中有一行内容,分别是Hello World! sha sha dan.,代码示意如下:

[root@pubserver ansible]# vim dayu.yml
---
- name: dayu file
  hosts: webservers
  tasks:
    - name: mkfile 2.txt
      copy:
        dest: /tmp/2.txt
        content: >
          Hello Word!
          sha sha dan.
[root@pubserver ansible]# ansible-playbook dayu.yml 

PLAY [dayu file] **********************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
ok: [web1]
ok: [web2]

TASK [mkfile 2.txt] *******************************************************************************************************************************
changed: [web2]
changed: [web1]

PLAY RECAP ****************************************************************************************************************************************
web1                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
web2                       : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
[root@web1 tmp]# cat /tmp/2.txt
Hello Word! sha sha dan.

留言

您的邮箱地址不会被公开。 必填项已用 * 标注