以下是我的脚本,用于循环定义新列表。
- name: "Set test result into list"
set_fact:
testList: "{{ testList|default([]) + [{'url': 'https://artifacts.com/artifactory/{{item}}.{{build_version}}.zip','name': '{{item}}.zip'}] }}"
with_items:
- "test1"
- "test2"
- "test3"
下面是结果
changed: [localhost] => (item={'url': u'https://artifacts.com/artifactory/test2.12.1.81.zip', 'name': u'test2.zip'})
changed: [localhost] => (item={'url': u'https://artifacts.com/artifactory/{{item}}.{{build_version}}.zip', 'name': u'{{item}}.zip'})
changed: [localhost] => (item={'url': u'https://artifacts.com/artifactory/{{item}}.{{build_version}}.zip', 'name': u'{{item}}.zip'})