ansible循环三

不羁岁月 提交于 2020-10-02 09:24:10

with_nested 采用笛卡尔乘积方式,将多个嵌套列表中的元素交叉组合

示例:
创建多个目录及子目录
mkdir -p /testdir/{a,b,c}/{1,2}

ansible剧本如下:


  • hosts: jack6_1
    remote_user: root
    gather_facts: no
    tasks:
    • file:
      path: "/testdir"
      state: directory

    • file:
      path: "/testdir/{{item.0}}/{{item.1}}"
      state: directory
      with_nested:
      • [a,b,c]
      • [t1,t2]






执行结果如下:
[root@jack7-1 work]# ansible jack6_1 -m shell -a "tree /testdir"
jack6_1 | CHANGED | rc=0 >>
/testdir
├── a
│   ├── t1
│   └── t2
├── b
│   ├── t1
│   └── t2
└── c
├── t1
└── t2











标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!