循环控制语句 之 with_nested

with_nested 和with_cartesian 实现的功能相同。嵌套循环可以理解为:

nest 英文嵌套
cartesian 英文笛卡尔积

for i in [1,2,3]:
    for j in ['a','b','c','d']:
        print(i,j)
- hosts: all
  tasks:
  - name: debug 
    debug:
      msg: "{{ item }}"
    with_nested:
    - [1,2,3]
    - ['a','b','c','d']
- hosts: all
  tasks:
  - name: debug 
    debug:
      msg: "{{ item }}"
    with_cartesian:
    - [1,2,3]
    - ['a','b','c','d']
posted @ 2023-01-20 09:38  mingtian是吧  阅读(79)  评论(0编辑  收藏  举报