我有两个变量:
如何获得指定位置的资产列表条目?
- debug:
var: assets[0]工作,但有硬编码的索引。
- debug:
var: assets[ asset_index ]给我The error was: 'list object' has no attribute '0'
- debug:
var: assets[ {{ asset_index }} ]给我template error while templating string: expected token ':', got '}'. String: {{ assets[ {{ asset_index }} ] }}'
发布于 2022-08-07 18:40:32
既然我已经提出了这个问题,我就可以更好地寻找一些解决办法了。在在Ansible Playbook中将字符串转换为整数的启发下,我尝试了
- debug:
var: assets[ asset_index | int ]...and到目前为止,我使用该过滤器设置变量,但它总是以字符串的形式返回。在Ansible中,您必须在使用值时执行转换,而不是在将其赋值给变量时执行转换。
https://serverfault.com/questions/1107619
复制相似问题