首页 > 其他 > 详细

ansible进阶循环

时间:2020-09-07 14:44:27      阅读:86      评论:0      收藏:0      [点我收藏+]
通过item和with_items 对重复操作进行循环执行

示例:


  • hosts: jack6_1
    remote_user: root
    gather_facts: no
    tasks:
    • name: touch file
      file:
      path: "{{item}}"
      state: touch
      with_items:
      • "a"
      • "b"
      • "c"

        在jack6_1主机上创建三个文件,由于是重复执行file模块,可以循环执行

        示例:

  • hosts: jack6_1
    remote_user: root
    vars:
    dirs:
    • "a"
    • "b"
    • "c"
      files:
    • "1"
    • "2"
    • "3"
      tasks:
      • name: remove dir
        file:
        path: "{{item}}"
        state: absent
        with_items: "{{dirs}}"
      • name: touch file
        file:
        path: "{{item}}"
        state: touch
        with_items: "{{files}}"
      • name: remove files
        file:
        path: "{{item}}"
        state: absent
        with_items: "{{files}}"

如下定义多个变量,重复执行某个模块

ansible进阶循环

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

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