Using variable in default filter in Ansible Jinja2

2019-02-20 03:29发布

Inside a an Ansible Jinja2 template I'm trying to set a "default" value which also has a variable in it but it's printing out the literal rather than interpolating it.

For example:

homedir = {{ hostvars[inventory_hostname]['instances'][app_instance]['homedir'] | default("/home/{{ app_instance }}/airflow") }}

returns:

airflow_home = /home/{{ app_instance }}/airflow

How to refer to the app_instance variable?

标签: ansible
1条回答
祖国的老花朵
2楼-- · 2019-02-20 04:25

Inside Jinja2 expression use Jinja2 syntax. You should concatenate strings to a variable value:

homedir = {{ hostvars[inventory_hostname]['instances'][app_instance]['homedir'] | default("/home/" + app_instance + "/airflow") }}
查看更多
登录 后发表回答