私は、決定されたセットのタスクの反復ごとに異なる変数セットを持つテンプレートを使用しようとしています。例えば、私はpostgresのための特定の値を設定したい課題の一つで:役割/ VARS/main.yamlでテンプレートでバリアブルでDictを使用可能にする
- name: Define values for postgres-ds
template:
src: postgres-ds.xml.j2
dest: /opt/ear_{{ instance_control.value }}/postgres-ds.xml
vars: "{{ postgres_desenv }}"
notify: Restart Service
を、私が定義された:
postgres_desenv:
var1: somevalue
var2: someothervalue
...
はそれでも、私が取得します次のエラー:
fatal: [rmt]: FAILED! => {
"failed": true,
"reason": "Vars in a Task must be specified as a dictionary, or a list of dictionaries
...
私は別のコンテキストで同じ変数を使用しようとすると、それが正常に動作します:
- debug:
msg: "{{ item.key }} - {{ item.value }}"
with_dict: "{{ postgres_desenv }}"
私はこのquestionの答えに従ってみましたが、まだ固まっています。テンプレート内すると
- name: Define values for postgres-ds
template:
src: postgres-ds.xml.j2
dest: /opt/ear_{{ instance_control.value }}/postgres-ds.xml
vars:
settings: "{{ postgres_desenv }}"
notify: Restart Service
:あなたはこのような何かを行うことができ
- name: Define values for postgres-ds
template:
src: postgres-ds.xml.j2
dest: /opt/ear_{{ instance_control.value }}/postgres-ds.xml
vars: postgres_{{ another_var }}
notify: Restart Service
あなたの答えは私の助けになりました。私はdictの他のフィールドを作成しました。これにより、コードの後半で変数を参照しやすくなりました。私はdictの代わりにdictsのdictを持っています。ありがとう。 –