2017-03-13 8 views
2

多くの変数を設定するAnsibleプレイブックがあります。Jinja2のAnsibleコンテキストに別のJinja2テンプレートを追加したい

- name: create config file 
template: 
src='templates/main_config.j2' 
dest="{{ tmp_dir }}/main_config.json" 

テンプレートmain_config.j2が親Ansibleプレイブックやタスク内の変数として定義されている文字列を書き込みます:一つのプレイブックは、このタスクを持っています。

Aniable変数の値に基づいて別のJinja2テンプレートを含める必要があります。

{% include "./templates/configurations.j2" %}, 
{% include "./templates/security.j2" %}, 
{% include './templates/' + {{ job }} + '_steps.j2' %} 

jobは、親のプレイブックに設定されている可能な変数です。

これは機能しません。何が問題なの?

答えて

5

ステートメント内の変数({% ... %})を参照するために、Jinja2式({{ ... }})を開く必要はありません。変数名は直接使用できます。

{% include './templates/' + job + '_steps.j2' %} 
関連する問題