Hi Kai,

that's interesting. It really is an integer, but how can I achieve it to 
print it like that?

For instance something like

- name: Foo
  hosts: all
  vars:
    test_int: 100
  tasks:
    - name: Print test_int
      debug:
        msg: "{{ test_int }}"


prints the value without brackets. So I guess it should be possible in 
general to just print numbers without any brackets.

TASK [Print test_int] 
***********************************************************************************************************************************************************************************************************
ok: [test] => {
    "msg": 100
}

Best regards,
Hauke

On Saturday, July 20, 2019 at 11:38:30 AM UTC+2, Kai Stian Olstad wrote:
>
> On 20.07.2019 10:13, hauke wrote: 
> > 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 
> > }}" 
> > 
>
> Don't filter it through to_json, following debugs will show that the value 
> is a int 
>
> - debug: msg={{ response.json.values.0.id | type_debug }} 
> - debug: msg={{ response.json | json_query('values[0].id') | type_debug }} 
>
>
> -- 
> Kai Stian Olstad 
>

-- 
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/07df4404-2c90-45c8-a4c7-d88dc5d0aaf9%40googlegroups.com.

Reply via email to