Git Product home page Git Product logo

Comments (3)

alessfg avatar alessfg commented on August 18, 2024 1

Interesting find! The default(omit) test case seems to be working as expected (as @oxpa pointed out), but in both that test and the next one it's true that Jinja2 returns a string instead of an int. This seems to be a "known" issue within Ansible, and there are a couple potential workarounds suggested here ansible/ansible#30366.

As to potential changes to this role -- I am adamant about keeping as many type checks as possible (and am always actively looking for more ways to enforce type checks), but I also see how the current implementation does not provide an ideal user experience.

There might be a way to check that the value is indeed an integer without resorting to the built-in number check? Maybe something along the lines of

{% if main['worker_rlimit_nofile'] is defined and main['worker_rlimit_nofile'] | int %}
worker_rlimit_nofile {{ main['worker_rlimit_nofile'] }};
{% endif %}

which in turn should fail if the value cannot be converted into an int? I'll test a few scenarios when I get a chance to see if this would be a viable solution. In the meantime, I suggest checking out the workarounds shared in the thread above 😄

from ansible-role-nginx-config.

oxpa avatar oxpa commented on August 18, 2024

If I get it correctly, the default filter works if the value is not set. Something like in the snipper below:

connections: "{{$env.value | default(30) }}" 

The default value of 30 will only be used if $env.value is not set.

In your case the value for nginx_worker_rlimit_noprofile exists. So the value of nginx_worker_rlimit_noprofile is used and the default filter doesn't really work at all.

Am I missing something here?

from ansible-role-nginx-config.

alessfg avatar alessfg commented on August 18, 2024

Heya! Finally got around doing some testing around this, and the tl;dr is that at this stage, I don't think I am going to change anything. The template will not apply the value if you use a string or try to convert the string to an int (like you did in your second test), but I am okay with that. At some stage in the hopefully near future, I plan to have variable validation, and using type checks is one of the ways variables will be validated.

The first test, which seems to be the root cause of the original issue, should work as intended as long as you comment out the "original" variable (otherwise, the default(omit) filter does not work as intended).

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.