私はAnsibleのプレイブックで作業しています。ここでは、テンプレートの中で辞書のリストである変数を置き換える必要があります。次のように可能なテンプレートの値の置換
タスクファイルは次のとおりです。
vars:
locations:
- context: "/rest"
server: "http://locahost:8080;"
- context: "/api"
server: "http://localhost:9090;"
tasks:
- name: testing the template
template:
src: ./conf.j2
dest: /tmp/test.conf
with_items: '{{ locations }}'
私はテンプレートにlocations
を代用する必要があります。
{% for location in item %}
location {{ location['context'] }}
proxy_pass {{ location['server'] }}
{% endfor %}
を次のように私は出力を期待していた:
location /rest
proxy_pass http://localhost:8080
location /api
proxy_pass htpp://localhost:9090
をしかし、私は、置換が正しい得ることに苦労しています、誰もが私はどこ指摘して助けることができるので、テンプレートは以下の通りです。間違いを起こす。 with_items
の、あなたが最初の反復になるよう、locations
リストの個々の要素を渡しているので、
私は取得していますエラーが、このとき
failed: [127.0.0.1] (item={u'context': u'/rest', u'server':
u'http://localhost:9090;'}) => {"failed": true, "item": {"context":
"/rest", "server": "http://localhost:8080;"}, "msg":
"AnsibleUndefinedVariable: 'context' is undefined"}
failed: [127.0.0.1] (item={u'context': u'/api', u'server':
u'http://locahost:8080;'}) => {"failed": true, "item": {"context":
"/api", "server": "http://locahost:9090;"}, "msg":
"AnsibleUndefinedVariable: 'context' is undefined"}
タイトルと最初の段落で述べた「置換」は正確にどこですか?私はここで置換を見ることができません。また、どのような結果が得られ、期待される結果でセミコロンに何が起こったのですか? – techraf
混乱して申し訳ありませんが、置換はテンプレートにあります。私は出力を期待していましたが、コードを何度か微調整した後、正しい出力が得られませんでした。実行中にエラーが発生するか、値がテンプレートに代入されない – Bidyut
SOルールに従って、正確なエラーメッセージまたは説明を投稿する必要があります。このフォームでは、質問を終了する必要があります。 – techraf