自动化运维工具 ansible(八)playbook中的判断
文章目录判断语句when 判断条件判断与test判断变量 的一些tests判断执行结果的一些tests判断路径的一些tests判断字符串的一些tests判断整数的一些tests其他的一些tests判断版本判断子集父集判断字符串判断数字条件判断与blockalways关键字条件判断与错误处理自定义报错信息failed_with关键字changed_when 关键字判断语句when 判断1....
·
文章目录
判断语句
when 判断
1.

2.

第二种写法
















条件判断与test
1.判断文件是否存在
2.脚本方式
3.







判断变量 的一些tests




判断执行结果的一些tests



判断路径的一些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
判断字符串的一些tests


判断整数的一些tests



其他的一些tests

判断版本



判断子集父集



判断字符串



判断数字


条件判断与block
1.














always关键字


always中的任务一定会被执行,无论block中的任务是否出错
条件判断与错误处理







自定义报错信息





when: ' "successful" not in return_value.stdout '
when: " 'successful' not in return_value.stdout "
failed_with关键字



changed_when 关键字








更多推荐




所有评论(0)