我必须执行大约20-25次这样的步骤。我该如何处理for循环(with_items)。
我可以预先定义参数URL1,Location1,pkg1.comamd1,$ pkg1.command2,并且可以在ansible剧本中定义它们。 Pkg1值将从jenkins脚本传递
- get_url:
url: "$URL1"
dest: $Location1
when: $Pkg1 != 'NONE'
- Name : run the commands
Shell: sh $pkg1.comamd1; sh $pkg1.command2
when: Pkg1 != 'NONE'
如何创建变量数组并使用_items完成
VarDetails {Pkg1, URL1, Location1, comamd1a, $command1b
Pkg2, URL2, Location2, comamd2a, $command2b
Pkg3, URL3, Location3, comamd3a, $command3b
....................
....................
}
答案 0 :(得分:0)
我尚未测试,但在使用项目列表时,它必须与以下参考示例配合使用。
- name: more complex items to add several users
user:
name: "{{ item.name }}"
uid: "{{ item.uid }}"
groups: "{{ item.groups }}"
state: present
with_items:
- { name: testuser1, uid: 1002, groups: "wheel, staff" }
- { name: testuser2, uid: 1003, groups: staff }
不要忘记通过更改
在变量前添加项目url: "$URL1"
dest: $Location1
到
url: "item.url"
dest: "item.location"
并且在with_items中引用时..使用变量$ URL1,$ URL2