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 }}獲取每次迭代的值。
