我在ansible group_vars / all中有以下数据结构:
group_vars / some_group.yml
my_group_var:
para_1:
type: aaaa
limit: bbbb
para_2:
type: cccc
limit: dddd
我如何阅读价值观?以下是工作代码:
set_fact:
new_var_1: my_group_var['para_1']['type']
new_var_2: my_group_var['para_1']['limit']
new_var_3: my_group_var['para_2']['type']
new_var_4: my_group_var['para_2']['limit']
但我想做类似下面的事情:
set_fact:
set new_var1 to new_var4(just like above)'{{ item }}'
with_items:
- my_group_var
答案 0 :(得分:0)
你走了:
---
- hosts: localhost
gather_facts: no
vars:
my_group_var:
para_1:
type: aaaa
limit: bbbb
para_2:
type: cccc
limit: dddd
tasks:
- set_fact:
"new_var_{{ item.0 * 2 }}": "{{ my_group_var[item.1]['type'] }}"
"new_var_{{ item.0 * 2 + 1 }}": "{{ my_group_var[item.1]['limit'] }}"
with_indexed_items: "{{ my_group_var.keys() }}"
- debug:
var: new_var_{{ item }}
with_sequence: start=0 end={{ (my_group_var.keys() | count) * 2 - 1 }}