循环控制语句 之 with_list

with_list

不展开循环嵌套的列表。功能类似于

for i in zip([1,2,3],['a','b','c']):
    print(i)
- hosts: all
  tasks:
  - name: debug
    debug:
      msg: "{{ item }}"
    with_list
    - ["a","b","c"]
    - [1,2,3]

而with_item 会展开循环,可以理解为

def with_item(obj):
    for i in obj:
        if isinstance(i ,list ):
            with_item(i)
        else:
            print(i)

with_item([[1,2,3],['a','b',['c','d']]])
posted @ 2023-01-20 09:29  mingtian是吧  阅读(35)  评论(0编辑  收藏  举报