首页 > 其他 > 详细

ansible循环三

时间:2020-09-07 08:08:07      阅读:83      评论:0      收藏:0      [点我收藏+]
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

ansible循环三

原文:https://blog.51cto.com/13434656/2529214

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!