判断语句
1. when 判断
2. 条件判断与test
(1) 判断文件是否存在
3. 判断变量 的一些tests
4. 判断执行结果的一些tests
5. 判断路径的一些tests
---
- hosts: test70
remote_user: root
gather_facts: no
vars:
testpath1: "/testdir/test"
testpath2: "/testdir/"
testpath3: "/testdir/testsoftlink"
testpath4: "/testdir/testhardlink"
testpath5: "/boot"
tasks:
- debug:
msg: "file"
when: testpath1 is file
- debug:
msg: "directory"
when: testpath2 is directory
- debug:
msg: "link"
when: testpath3 is link
- debug:
msg: "link"
when: testpath4 is link
- debug:
msg: "mount"
when: testpath5 is mount
- debug:
msg: "exists"
when: testpath1 is exists
6. 判断字符串的一些tests
7. 判断整数的一些tests
8. 其他的一些tests
判断版本
判断子集父集
判断字符串
判断数字
9. 条件判断与block
10. block结合always关键字
always中的任务一定会被执行,无论block中的任务是否出错
11. 条件判断与错误处理
自定义报错信息
when: ' "successful" not in return_value.stdout '
when: " 'successful' not in return_value.stdout "