A little background on what I am trying to accomplish. I am pulling a query via JSON and submitting to another API(Servicedesk). Every time I submit to service desk, the item variable is to be processed as a string. I need the quotes removed for submission. I have tried converting to (INT) and the data continues to be processed as a string. If I manually set the variable to the number it will submit correctly. here is what my output currently looks like.
(Grabbed from -vvv ansible output)
“customfield_1705”: “421266”
and here is what i need it to look like
“customfield_1705”: 421266 (Requirement of servicedesk)
In the normal course of things the result of Jinja templating is always a string (even for cases where it looks like it isn’t, that’s because Ansible converted it from a string into something else after templating.)
This isn’t a great user experience for Ansible, where a large number of non-string types are used, so there is a (currently optional) feature to enable preservation of types during templating. This will be the default in the future, but for now you can enable it if necessary. Ansible Configuration Settings — Ansible Community Documentation
Unfortunately this has the potential to break existing content that relied on the previous behaviour, so it requires careful testing to make nothing’s subtly wrong with this configuration enabled.
As an alternative, you can template more of the structure; since Ansible will parse a string that represents a dict back into a data structure, this can contain more types.
The trick is to always cast at consumption, if you do this in intermediate steps you might still get ‘stringified’, using the ‘native’ engine minimizes this but does not remove it. An upcoming change to the core way Ansible deals with types (Data Tagging) will hopefully fix this going forward.