Ansible Loop循环控制
Ansible 2.5开始就可以使用loop来创建循环。
示例1 数组循环:
tasks:
- name: create user
user:
name: {{ item }}
loop:
- user01
- user02
- user03
示例2 字典循环:
tasks:
- name: create user and group
user:
name: {{ item.name }}
group: {{ item.groups }}
loop:
<span><span><span><span><span><span><span><span><span><span> - name<span><span>:<span><span> <span><span>‘testuser1‘</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span> groups<span><span>:<span><span> <span><span>‘wheel‘<span><span><span><span><br /></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span><span><span><span> -<span><span> <span><span><span><span>name<span><span>:<span><span> <span><span>‘testuser2‘</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
<span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span><span> groups<span><span>:<span><span> <span><span>‘root‘<span><span><span><span><br /></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
未完待续...