循环控制语句 之 with_items
示例1
可以理解为:
for item in groups.ungrouped:
print(item)
- hosts: all
tasks:
- name: debug
debug:
msg: "{{ item }}"
with_items: "{{ groups.ungrouped }}"
- hosts: all
tasks:
- name: debug
debug:
msg: "{{ item }}"
with_items:
- "user01"
- "user02"
示例2
可以理解为:
a=[{user: test01,passwd: 123},{user: test02,passwd: 123}]
for item in a:
print(item['name'])
- hosts: all
tasks:
- name: debug
debug:
msg: "your name is {{ item.user }},password is {{ item.passwd }}"
with_items:
- {user: test01,passwd: 123}
- {user: test02,passwd: 123}