0

テンプレートで、辞書のリストである変数を置き換える必要がある 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

しかし、私は置換を正しく行うのに苦労しています。どこで間違いを犯しているのかを指摘するのを手伝ってくれる人はいますか?

私が得ているエラーは

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"}
4

1 に答える 1