title: How to replace Jinja2 expressions inside expressions?
body: <p>I'm using Ansible templates and I'm importing variables from an external file <code>app_vars.yml</code>:</p>
  
  <pre><code># App list
  apps:
  - app1
  
  # App1 vars
  app1:
    environments:
    - demo
    - test
    filebeat_properties:
      paths:
      - /home/_env_-app/logs/_env_-*.log
      fields:
        app_id: _env_
  </code></pre>
  
  <p>In the template <code>filebeat_template.yml</code> I'm currently just replacing the <code>_env_</code> string with <code>env</code> from the <code>for</code> loop using the <code>replace()</code> filter like this:</p>
  
  <pre><code>{% for app in apps %}
    {% for env in vars[app]["environments"] %}
  - type: log
    enabled: true
    {{ vars[app]["filebeat_properties"] | to_nice_yaml(indent=2, width=9999) | indent(2) | replace("_env_", env) }}
    {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>But I was wondering is there some syntax that lets me mark the Jinja expression-to-be-replaced in the <code>app_vars.yml</code> file? Kind of like this</p>
  
  <pre><code>...
  paths:
  - /home/{{ env }}-app/logs/_env_-*.log
  fields:
    app_id: {{ env }}
  </code></pre>
  
  <p>where <code>{{ env }}</code> is to be replaced in the template file with the <code>for</code> loop <code>env</code> variable? Adding <code>""</code> around it makes it just a string.<br>
  Thanks!</p>