私は次のような配列変数を持っています
registries:
- type: primary
host: r1.example.com
- type: secondary
host: r2.example.com
json.j2
テンプレート内の各配列アイテムからのみホスト属性をレンダリングしたい。テンプレートで次のことを試しました。
{
"insecure-registries": {{ registries | map(attribute='host') | to_json }}
}
残念ながら、それは機能しませんが、プレイブックの実行中にこのエラーをスローします:
AnsibleError:予期しないテンプレートタイプエラーが発生しました({\ n \ "graph \":\ "{{docker_home}} \"、\ n \ "insecure-registries \":{{registries | map(attribute = 'host') | to_json}} \ n}):タイプ 'generator'のオブジェクトはJSONシリアル化できません "}
map
リストではない特定のオブジェクトタイプを返します。フィルタを使用to_json
してフィードする前に、それをリストに変換する必要がありlist
ます
{
"insecure-registries": {{ registries | map(attribute='host') | list | to_json }}
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加