通过item和with_items 对重复操作进行循环执行
示例:
- hosts: jack6_1remote_user: rootgather_facts: notasks:
- name: touch filefile:path: "{{item}}"state: touchwith_items:
- "a"
- "b"
- "c"
在jack6_1主机上创建三个文件,由于是重复执行file模块,可以循环执行
示例:
- name: touch filefile:path: "{{item}}"state: touchwith_items:
- hosts: jack6_1remote_user: rootvars:dirs:
- "a"
- "b"
- "c"files:
- "1"
- "2"
- "3"tasks:
- name: remove dirfile:path: "{{item}}"state: absentwith_items: "{{dirs}}"
- name: touch filefile:path: "{{item}}"state: touchwith_items: "{{files}}"
- name: remove filesfile:path: "{{item}}"state: absentwith_items: "{{files}}"
精彩评论