我有一个数组变量如下
registries:
- type: primary
host: r1.example.com
- type: secondary
host: r2.example.com
我只想从json.j2
模板中的每个数组项呈现host属性。
我在模板中尝试了以下操作:
{
"insecure-registries": {{ registries | map(attribute='host') | to_json }}
}
不幸的是,它不起作用,但在运行playbook时抛出此错误:
AnsibleError: Unexpected templating type error occurred on ({ \n \"graph\": \"{{ docker_home }}\",\n \"insecure-registries\" : {{ registries | map(attribute='host') | to_json }}\n}): Object of type 'generator' is not JSON serializable"}
map
返回不是列表的特定对象类型。在使用list
过滤器将其馈送到to_json
之前,需要将其转换为一个列表相关问题 更多 >
编程相关推荐