Giter VIP home page Giter VIP logo

Comments (8)

jainnikhil30 avatar jainnikhil30 commented on June 12, 2024 1

@leedm777

This is not a module issue. This is because you are using jinja templating. Unfortunately due to how jinja2 works, it technically only has the ability to return strings. Any time you use jinja2 templating, the result comes out as a string. So while |int is internally converting the value to an int, the final result from jinja2 is a string. This has been discussed here: ansible/ansible#30366

The good news is there was a change implemented in jinja to preserve the native types. You can add the following in the [default] section of ansible.cfg

jinja2_native = True

With above, integer value wont convert to a string, while using jinja template. You also dont need a int filter now. Can you please try that. I was able to use your playbook (minus the int filter) successfully with above change in ansible.cfg

from community.aws.

goneri avatar goneri commented on June 12, 2024 1

Thank you @jainnikhil30 for the long answer. The jinja2_native configuration key is documented here https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-jinja2-native and requires Ansible 2.7 or greater and an up to date version of Jinja2 (>= 2.10).

@leedm777 I close the PR, feel free to reopen if you think we've missed something.

from community.aws.

sky-amoncadot avatar sky-amoncadot commented on June 12, 2024 1

Is there a way to do jinja2_native on just one task or play? I have a huge stack of playbooks that all expect the default behavior. Changing it so this one value converts correctly then breaks dozens of other tasks.

Based on the documentation that @goneri sent here, you can configure the environment variable at the task level so that this does not effect the entire playbook/play:

ANSIBLE_JINJA2_NATIVE: true

from community.aws.

Akasurde avatar Akasurde commented on June 12, 2024

@leedm777 Let us know if @jainnikhil30's solution works for you? Thanks.

from community.aws.

leedm777 avatar leedm777 commented on June 12, 2024

@jainnikhil30, enabling jinja2_native does indeed work.

Although given Jinja2's default behavior of "everything returns a string", I would've expected either Ansible or the module itself to be more lenient and parse strings that get passed in for numeric fields. That said, I'm good with enabling jinja2_native and moving on.

Thanks!

from community.aws.

ansibullbot avatar ansibullbot commented on June 12, 2024

cc @jillr @s-hertel @tremble @wimnat
click here for bot help

from community.aws.

eightnoneone avatar eightnoneone commented on June 12, 2024

Is there a way to do jinja2_native on just one task or play? I have a huge stack of playbooks that all expect the default behavior. Changing it so this one value converts correctly then breaks dozens of other tasks.

from community.aws.

eightnoneone avatar eightnoneone commented on June 12, 2024

@sky-amoncadot I very much appreciate the reply as I went looking for that specific understanding and have still yet to find documentation that clearly explains how one changes a configuration setting at the task level. I know it's a tangent to this issue, but how does one infer from Ansible Configuration Settings which of the keys used in a playbook keyword context?

  • The section is labeled DEFAULT_JINJA2_NATIVE
  • The ini key is jinja2_native
  • The env var is ANSIBLE_JINJA2_NATIVE

Searching on other settings I've seen altered in plays, like become_user, I'm guessing it's the ini key of jinja2_native. I'm up for doing the documentation PR myself, but it just struck me odd that it's assumed knowledge.

from community.aws.

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.