Code Monkey home page Code Monkey logo

Comments (9)

 avatar commented on September 23, 2024

i tried copying and modifying the similiar logic in the other other templates

   {% if v != "" %}{{ v.replace(";",";\n      ").replace(" {"," {\n      ").replace(" }"," \n   }\n") }}{% if v.find('{') == -1%};

but that code looks like it would have problems with semicolons within strings , as there's no code to check of the semicolin is within a quoted string and thus should ignore it.

from ansible-role-nginx.

jdauphant avatar jdauphant commented on September 23, 2024

Hi @jrobeson ,
Sorry for the late response on that, you can do something like that :

 bar: 
   - |
     map $scheme $hsts_header {
         https 'max-age=10886400; includeSubDomains;'
     }

In yaml "|" is a string where new lines are keeped.
Normaly it's works but produce ugly conf.
You can test this commit that produce good conf input :
362b995
It's you see not problem with the commit, I will merge it to master.

What do you thinks ?
Thanks in advance for you anwser

from ansible-role-nginx.

jdauphant avatar jdauphant commented on September 23, 2024

I close the ticket it's now supported in the version 1.2 :

- |
     map $scheme $hsts_header {
         https 'max-age=10886400; includeSubDomains;'
     }

Thanks for your help @jrobeson

from ansible-role-nginx.

chanon avatar chanon commented on September 23, 2024

Sorry to comment on this old issue, but was just wondering why the v.replace(";",";\n ") part is needed. A lot of http headers can have semicolons in them.

Just as an example, after updating some things in my code base, my Content-Security-Policy started having problems and I tracked it down to the extra \n inserted in the semicolons in it.

I removed the replace(";",";\n ") in my local copy, but am wondering what it is needed for.

from ansible-role-nginx.

jdauphant avatar jdauphant commented on September 23, 2024

@chanon It's for that you have a second notation: you can see a exemple of the new notation in my last message.

Change apply to each notation

Old notation:

{% if v != "" %}{{ v.replace(";",";\n ").replace(" {"," {\n ").replace(" }"," \n }\n") }}{% if v.find('{') == -1%}; {% endif %}{% endif %}

New notation:

{{v.replace("\n","\n ")}}

from ansible-role-nginx.

jdauphant avatar jdauphant commented on September 23, 2024

Hey @chanon, did you get your answer in my last message ?

Also replace(";",";\n ") was introduced to have good output file.

from ansible-role-nginx.

ElRoberto538 avatar ElRoberto538 commented on September 23, 2024

I don't think this issue is resolved? The /templates/nginx.conf.j2 file http block is

http {
        include {{ nginx_conf_dir }}/mime.types;
        default_type application/octet-stream;
{% for v in nginx_http_params %}
        {{ v }};
{% endfor %}

        include {{ nginx_conf_dir }}/conf.d/*.conf;
        include {{ nginx_conf_dir }}/sites-enabled/*;
}

Which adds a semicolon to every http parameter - including the map block which will then fail as it shouldn't have a semicolon. @jrobeson seems to have suggested replacing it with the block from site.conf.j2, which I did, and it now works (unsure if it breaks in other scenarios):

http {
        include {{ nginx_conf_dir }}/mime.types;
        default_type application/octet-stream;
{% for v in nginx_http_params %}
    {% if v.find('\n') != -1 %}
        {{v.replace("\n","\n   ")}}
    {% else %}
        {% if v != "" %}{{ v.replace(";",";\n      ").replace(" {"," {\n      ").replace(" }"," \n   }\n") }}{% if v.find('{') == -1%};
    {% endif %}{% endif %}{% endif %}
{% endfor %}

        include {{ nginx_conf_dir }}/conf.d/*.conf;
        include {{ nginx_conf_dir }}/sites-enabled/*;
}

from ansible-role-nginx.

jdauphant avatar jdauphant commented on September 23, 2024

Hello @ElRoberto538 ,
It was already propose #141 .
We haven't merge it to promote "nginx_configs" variable instead.

from ansible-role-nginx.

ElRoberto538 avatar ElRoberto538 commented on September 23, 2024

@jdauphant Ah, right... Thanks for that, I don't know how I missed that. At least now there's a link for others to hopefully not make the same mistake as me!

from ansible-role-nginx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.