debops/ansible-nginx

Welcome url scheme template not being parsed correctly... moustaches in deployed file

bryanbecker opened this issue · 7 comments

I'm getting the following in my public/index.html:

  <body>
    <div id="content">

      <h2><a href="{{ item.welcome_url_scheme|d("https") }}://myurl.com/">myurl.com</a></h2>

      <p id="http-status"><strong>418 I'm a teapot</strong></p>

    </div>
  </body>
</html>

Clearly the following section of .j2 code is not being parsed how it was intended, but not sure why:

{% if nginx_tpl_domain %}
{%   set nginx_tpl_welcome_title = '<a href="{{ item.welcome_url_scheme|d("https") }}://' + nginx_tpl_domain + '/">' + nginx_tpl_domain + '</a>' %}
{% elif not nginx_tpl_domain %}
{%   set nginx_tpl_welcome_title = '<a href="http://companyname.website/">CompanyName.website</a>' %}
{% endif %}

What Ansible version do you use? Can you try with Ansible 2.2?

That was 2.2

I'm testing now on a different, clean host.

Confirming the same result

{% set nginx_tpl_welcome_title = '<a href="{{ item.welcome_url_scheme|d("https") }}://' + nginx_tpl_domain + '/">' + nginx_tpl_domain + '</a>' %}

After further consideration, the error is almost surely because you can't put a variable expression ({{) inside a statement ({%)

I think something like this might work:

{% set nginx_tpl_welcome_title %}
   <a href="{{ item.welcome_url_scheme|d("https") }}://{{ nginx_tpl_domain }}/"> {{ nginx_tpl_domain }} </a>
{% endset %}

I tested the above fix locally and it works

Not sure why the travis tests are failing. The error is:

template error while templating string: expected token '=', got 'end of statement block'

Any ideas?

Not sure yet, I will try to investigate it on latest Ansible 2.2.