Comments (4)
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.
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.
Hm that could work for the time being. Mind submitting a PR?
from ansible-role-nginx-config.
PR merged 😄
from ansible-role-nginx-config.
Related Issues (20)
- Task nginxinc.nginx_core.nginx_config fails due to undefined variable HOT 1
- Add support for the NGINX real_ip module
- how to insert an if statement in the server stanza HOT 3
- How to omit load_module: modules/ngx_http_js_module.so HOT 3
- mime.types not included in default nginx configuration HOT 4
- Add `include` support in default.conf.j2 template HOT 1
- Templating error HOT 2
- "mappings" from the "map" directive are not applied to a resulting configuration HOT 2
- Role should restart/reload Nginx when SSL certificates change HOT 3
- How to set "global" variables in the HTTP context HOT 5
- Allow nginx.conf.j2 to create gzip settings HOT 2
- Nested location HOT 2
- Question - nginx-config and proxy rewrite HOT 4
- Question - QUIC config HOT 5
- Enforcing numeric types breaks certain templating patterns. HOT 3
- http2 directive uses enable but http3 uses enabled
- Variables for gzip_static HOT 1
- Logrotate does not format correctly HOT 2
- add map inside stream HOT 3
- Validate configuration HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-role-nginx-config.