Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix native type conversion in json_template #154

Merged
merged 4 commits into from
Oct 9, 2018

Conversation

ganeshrn
Copy link
Member

@ganeshrn ganeshrn commented Oct 6, 2018

Fixes #151

  • The current json_template implementation tries to convert the value to int irrespective to the
    actual type of data.

  • Ansible version 2.7 onwards supports native jinja2 types conversion. Refer JSON templating incorrectly changes the value to type int #151 (comment)
    eg: value: "{{ item.name.acl_name|float }}"

  • To convert to native jinja2 type by default need to set jinja2_native config varaible in defaults
    section of active Ansible config file.

Note: This feature require jinja2 version to be >= 2.10

@ganeshrn ganeshrn changed the title Fix native type comnversion in json_template Fix native type conversion in json_template Oct 6, 2018
Fixes ansible-network#151

*  The current implementation tries to convert the value
   to int irrespective to the actual desired type of data.
*  Ansible version 2.7 onwards supports native jinja2 types
   eg: value: "{{ item.name.acl_name|float }}"
   To convert to native jinja2 type by default need to set
   `jinja2_native` config varaible in `defaults` setion within
   configuration file.
   Note: this required jinja2 version to be >= 2.10
@ganeshrn ganeshrn force-pushed the json_template_value_fix branch from ab2b443 to af60ec2 Compare October 6, 2018 09:51
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@trishnaguha
Copy link
Member

trishnaguha commented Oct 8, 2018

@ganeshrn We need to put this in Doc that this feature is only supported with Ansible 2.7 and requires jinja2 version to be >= 2.10. This cannot be backported.
And example how one can still convert it into type int in the parser_template

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.


**Note**
Native jinja2 datatype (eg. 'int', 'float' etc.) rendering is supported with Ansible version >= 2.7
and jinja2 library version >= 2.10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add an example?

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@trishnaguha trishnaguha merged commit a83d5c2 into ansible-network:devel Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants