让我们在默认角色defaults/main.yml文件中添加以下内容:
num: 0
config:
0:
a: true
b: 'x'
1:
a: false
b: 'y'
2:
a: false
b: 'z'
我现在在playbook调用中发送了-e num=1
, 我想在角色的其他地方使用基于这个值的a
和b
,例如:
aValue: '{{config[num].a}}'
bValue: '{{config[num].b}}'
我该怎么做?我试过使用
aValue: '{{config[num].a}}'
但是出现了错误:'dict object' has no attribute u'1'
aValue: '{{config["num"].a}}'
但是出现了错误:'dict object' has no attribute 'num'