ansible中的常用循环模块with_items

ansible中的循环模块有很多,不过with_items最为常用,且较为简单,循环模块最多的功能就是将重复性的任务简单化,如下例子所示:

- hosts: all
  remote_user: root
  vars:
    working_dir: "/home/root/deploy/rap"
tasks:
- name: create working_dir directory file: path: "{{ item }}" state: directory with_items: - "{{ working_dir }}"

with_items可以用于迭代一个列表或字典,通过{{ item }}获取每次迭代的值。

posted @ 2019-05-04 16:12  峰哥ge  阅读(9923)  评论(1编辑  收藏  举报