I set a variable from a previous play that collects a value (integer), then call it in the following task using the uri module to pass it via API. But I always get a 422 error back saying "Value should be integer".
- name: Deploy Staging Blueprint
local_action:
module: uri
url: "https://{{ server_address }}/api/application/{{app_id}}/deploy"
method: PUT
status_code: 202
validate_certs: no
headers:
Content-Type: 'application/json'
Accept: 'application/json'
AUTHTOKEN: "{{ server_session.token }}"
body_format: json
body:
version: "{{ staging.json.version }}"
run_once: true
register: deploy
changed_when: deploy|succeeded
I first tried converting it to integer with "| int" but that didnt work. I then tried "| type_debug" and validated the variable is an integer.
But I still get this error. If I replace the variable with a raw integer it works just fine. Using verbose output it still appears the value is being passed as a string.
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": {
"version": "48"
},
"body_format": "json",
Any idea what Im missing here or how I can work around this? Im currently running Ansible 2.4.0 for this project.
Yes, this is a really strange default behavior of Ansible. It renders every value as string regardless its original type. So you end up with staging.json.version being a string instead of a numeric type.
This behavior can be altered in recent Ansible releases using the jina2_native flag globally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With