本文共 1436 字,大约阅读时间需要 4 分钟。
hosts: test
gather_facts: Falsevars:list: [1,2,3,4,5]one: "1"str: "string"tasks:name: run commands
shell: df -hregister: infoname: debug pprint filter
debug: msg="{ { info.stdout | pprint }}"name: debug conditionals filter
debug: msg="The run commands status is changed"when: info|changedname: debug int capitalize filter
debug: msg="The int value { { one | int }} the lower value is { { str | capitalize }}"name: debug default filter
debug: msg="The Variable value is { { ansible | default('ansible is not define') }}"name: debug list max and min filter
debug: msg="The list max value is { { list | max }} The list min value is { { list | min }}"name: debug random filter
debug: msg="the list ramdom value is { { list | random }} and generate a random value is { { 1000 | random(1,10) }}"name: debug join filter
debug: msg="the join filter value is { { list | join("+") }}"第1个info.stdout结果使用pprint filter进行格式化
第2个是对info的执行状态使用changed filter进行判断第3个是对one的值进行int转变,然后对str的值进行capitalize格式化第4个是对ansible变量进行判断,如果该变量定义了就引用它的值,如果没有定义就使用default内值第5个是对list内的值进行最大值max和最小值取值第6个是对list内的值使用random filter随机挑选一个,然后随机生成1000以内的数字,step是10第7个是对list内的值使用join filter连接在一起.第8个是对str值使用replace与regex_replace替换转载于:https://blog.51cto.com/yangxiongchun/2072140