-
Notifications
You must be signed in to change notification settings - Fork 53
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
JSON templating incorrectly changes the value to type int #151
Comments
Can you please share the parser template |
This is the parser template, it is available as
The prefix list output variable contains the following:
|
Fixes ansible-network#151 * Add support for type option in json_template
Please ignore above comment. |
@ganeshrn This seems to work when the This is the one that works as expected:
The other uses of json_template do not, for example:
Results in output like this:
|
Yes that’s right. The fix I proposed earlier is not correct that’s why I have closed the PR. I am working on alternate way to fix the issue. |
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
@lancewood1 Ansible 2.7 version onwards supports native jinja2 datatype conversion, hence handling of native type conversion is not required in the To enable native jinja2 conversion enusre Ansible versions is >= 2.7 and jinja2 version is >=2.10
With this fix if in case you want to convert the value to
Output:
|
* Fix native type conversion in json_template Fixes #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 * Fix CI failure * Update doc * Add example usage in doc
ISSUE TYPE
SUMMARY
The
_coerce_to_native
function innetwork-engine/lib/network_engine/plugins/template/__init__.py
incorrectly casts values to type integer.
Any string value that looks like an integer is turned into an integer which causes issues. Many network constructs should not be converted from type string. For example, an ip prefix-list defined on a Cisco device could have a name similar to "0012345678" however once the that value goes through this process the prefix-list name is change to 12345678 of type integer.
The line
value = int(value)
is changing the variable type of objects that should be strings.STEPS TO REPRODUCE
EXPECTED RESULTS
prefix_list["0012345678"] is defined
ACTUAL RESULTS
prefix_list[12345678] is defined
The text was updated successfully, but these errors were encountered: