Hi there,
Currently I try to fetch an integer value of an API and to use that exact
value later on to create an object via the same API. The problem is, the
API only accepts JSON numbers (integer in this case) as input. Is there any
way to tell Ansible to save a value as a "true" integer without the
brackets?
My tasks:
- name: Foo
hosts: all
tasks:
- name: Get the JSON object
uri:
url: https:
//jira.foo.bar/rest/agile/1.0/board/219/sprint?state=active
user: "{{ username }}"
password: "{{ password }}"
force_basic_auth: yes
body_format: json
register: response
delegate_to: localhost
- name: Show important part of response
debug:
msg: "{{ response.json }}"
- name: Try to filter out ID without brackets
debug:
# msg: "{{ response.json |json_query('values[0].id') |int }}"
# msg: "{{ response.json |json_query('values[0].id') }}"
# msg: "{{ response.json |json_query('values[0].id') | to_json }}"
# msg: "{{ response.json |json_query('values[0].id') | to_json |int
}}"
msg: "{{ response.json |json_query('values[0].id') | int | to_json
}}"
This is the output of the first debug task where *values[0].id* is *341*
TASK [Show important part of response]
****************************************************************************************************************************************************************************************************************************************
ok: [test] => {
"msg": {
"isLast": true,
"maxResults": 50,
"startAt": 0,
"values": [
{
"endDate": "2019-07-22T12:00:00.000+02:00",
"goal": "",
"id": 341,
"name": "2019 KW 29",
"originBoardId": 1,
"self": "https://jira.foo.bar/rest/agile/1.0/sprint/341",
"startDate": "2019-07-15T12:00:21.585+02:00",
"state": "active"
}
]
}
}
This is the output of any try of the second debug task, *values[0].id* is
every time *"341"*
TASK [Try to filter out ID without brackets]
**********************************************************************************************************************************************************************************************************************************
ok: [test] => {
"msg": "341"
}
But the API doesn't accept a value of *"341"*, it needs a JSON number
instead of a string.
Is there anything I can do to achieve that?
Best regards,
Hauke
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/de9d4aeb-2b8c-419c-8ac9-f54a7f2a498f%40googlegroups.com.