1. exists和not exists
exists:
[root@server4 pd]# cat pd3.yml
---
- hosts: testB
remote_user: root
gather_facts: no
vars:
testpath: /testdir
tasks:
- debug:
msg: "file exist"
when: testpath is exists
测试:
[root@server4 pd]# ansible-playbook pd3.yml
PLAY [testB] *******************************************************************
TASK [debug] *******************************************************************
ok: [172.25.60.3] => {
"msg": "file exist"
}
not exists:
格式1:
[root@server4 pd]# cat pd3.yml
---
- hosts: testB
remote_user: root
gather_facts: no
vars:
testpath: /testdirhs
tasks:
- debug:
msg: "file is not exist"
when: testpath is not exists
格式2:
[root@server4 pd]# cat pd3.yml
---
- hosts: testB
remote_user: root
gather_facts: no
vars:
testpath: /testdirhs
tasks:
- debug:
msg: "file is not exist"
when: not testpath is exists
测试:
[root@server4 pd]# ansible-playbook pd3.yml
PLAY [testB] ***************************<