|
---
- hosts: salt-master
tasks:
- name: with_items,参数为列表,列表元素为字符串或字典
debug: msg='`item`.`name` and `item`.`age`'
with_items:
- {name: 'lixc',age: 25}
- {name: 'liss',age: 24}
when: 1
- name: with_nested,打印嵌套列表,参数为列表,列表元素为列表
debug: msg='{{item[0]}} and {{item[1]}}'
with_nested:
- ['lixc','liss']
- [1,2]
when: ansible_os_family == "Debian"
- name: with_dict,循环字典,参数为字典
debug: msg='`item`.`key` and `item`.`value`'
with_dict:
ansible:
cmd: commandline
ply: playbooks
salt:
cmd: commandline
st: state
when: ansible_os_family == "Debian" and "8"|int >= 6
- name: with_fileglob,遍历文件夹下的文件,不包括文件夹,roles可为相对路径
debug: msg=`item`
with_fileglob:
- /tmp/test1/*
- /tmp/test2/*
when: lixc is not defined
- name: with_sequence,获得整数序列
debug: msg=`item`
with_sequence: start=4 end=8 stride=2
when: 1 in [1,2,3] |
|
|