合并列表和值的 Ansible 对象列表
Ansible object list from merging a list and a value
给定一个字符串列表
list:
- a
- b
和一个字符串
str: c
如何获得与第一个列表元素个数相同的对象列表,结构如下?:
new_list:
- list_key: a
str_key: c
- list_key: b
str_key: c
此外,我正在使用 Ansible 2.8
例如
- set_fact:
new_list: "{{ list|
map('regex_replace', '^(.*)$', '{list_key: \1}')|
map('from_yaml')|
map('combine', {'str_key': str})|
list }}"
给定一个字符串列表
list:
- a
- b
和一个字符串
str: c
如何获得与第一个列表元素个数相同的对象列表,结构如下?:
new_list:
- list_key: a
str_key: c
- list_key: b
str_key: c
此外,我正在使用 Ansible 2.8
例如
- set_fact:
new_list: "{{ list|
map('regex_replace', '^(.*)$', '{list_key: \1}')|
map('from_yaml')|
map('combine', {'str_key': str})|
list }}"