我必须像这样运行20-25次这样的步骤。如何处理for循环(with_items)。
我可以预先定义参数URL1,Location1,pkg1.comamd1,$pkg1.command2,我可以在ansible实战手册中定义它们。将从jenkins脚本传递Pkg1值
- get_url:
url: "$URL1"
dest: $Location1
when: $Pkg1 != 'NONE'
- Name : run the commands
Shell: sh $pkg1.comamd1; sh $pkg1.command2
when: Pkg1 != 'NONE'
如何创建变量数组并执行with_items操作
VarDetails {Pkg1, URL1, Location1, comamd1a, $command1b
Pkg2, URL2, Location2, comamd2a, $command2b
Pkg3, URL3, Location3, comamd3a, $command3b
....................
....................
}
发布于 2019-10-29 01:12:07
我还没有测试,但它必须在使用项目列表时与以下参考示例一起工作。
- 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中引用的时候..使用您的变量$URL2 $URL1
https://stackoverflow.com/questions/58592335
复制相似问题