Git Product home page Git Product logo

Comments (4)

alessfg avatar alessfg commented on July 18, 2024

I do not have any suggestions right now. As you mentioned, lists seem to be the way to go, but it'd be a BC. That being said, as part of an upcoming templating refactor I'm planning on switching to lists whenever possible and that should fix this issue.

from ansible-role-nginx-config.

StudioMaX avatar StudioMaX commented on July 18, 2024

I had an idea to implement sorting by IP and port to somehow preserve the relation of IP addresses in the config.
Current:
https://github.com/nginxinc/ansible-role-nginx/blob/0922304b12c2dc578f86537f311304ffc498057d/templates/http/default.conf.j2#L82-L84

What I did locally:

{% for listen in (item.value.servers[server].listen.values() | rejectattr("ip", "defined") | sort(attribute='port') + item.value.servers[server].listen.values() | rejectattr("ip", "undefined") | sort(attribute='port') | sort(attribute='ip')) %}
    listen {% if listen.ip is defined and listen.ip | length %}{{ listen.ip }}:{% endif %}{{ listen.port }}{% if listen.ssl is defined and listen.ssl %} ssl{% endif %}{% if listen.opts is defined and listen.opts | length %} {{ listen.opts | join(" ") }}{% endif %};
{% endfor %}

I'm not sure about portability, but it works for me.

So listen will be rendered as:

  • First, show everything where the IP is not specified
  • Sort them only by port
  • Second, show everything where IP and port is specified
  • Sort them by IP, then by port (like "order by ip.asc, port.asc")

Results:

    listen 8787 default_server;
    listen 1.2.3.4:80 default_server deferred;
    listen 1.2.3.4:443 ssl http2 default_server deferred;
    listen 1.2.3.4:5757 default_server;
    listen [fe80::a00:abcd::aaaa]:80 default_server deferred;
    listen [fe80::a00:abcd::aaaa]:443 ssl http2 default_server deferred;
    listen [fe80::a00:abcd::bbbb]:80 default_server deferred;
    listen [fe80::a00:abcd::bbbb]:443 ssl http2 default_server deferred;
    listen [fe80::a00:abcd::cccc]:5757 default_server;

from ansible-role-nginx-config.

alessfg avatar alessfg commented on July 18, 2024

Hm that could work for the time being. Mind submitting a PR?

from ansible-role-nginx-config.

alessfg avatar alessfg commented on July 18, 2024

PR merged 😄

from ansible-role-nginx-config.

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.