Is there any reason you can't just use result.stdout.access_token?

$ cat debug-token.yml
- name: debug vars
  hosts: localhost
  gather_facts: no

  vars:
    result:
      stdout:
        access_token: xxxxxxxxxx
        expires_in: 4320
        token_type: yyyyyyyyyy

  tasks:
    - name: debug the result
      ansible.builtin.debug:
        var: result

    - name: extract the token
      ansible.builtin.debug:
        msg: "{{ result.stdout.access_token }}"


$ ansible-playbook debug-token.yml

PLAY [debug vars]
**********************************************************************************************************

TASK [debug the result]
****************************************************************************************************
ok: [localhost] => {
    "result": {
        "stdout": {
            "access_token": "xxxxxxxxxx",
            "expires_in": 4320,
            "token_type": "yyyyyyyyyy"
        }
    }
}

TASK [extract the token]
***************************************************************************************************
ok: [localhost] => {
    "msg": "xxxxxxxxxx"
}


On Sat, 14 Oct 2023 at 13:43, Veera <sveem...@gmail.com> wrote:

> I need only the output or the value of the below(trying to set_fact the
> access_token)
> access_token": "xxxxxxxxxx"
>
>
>
>
> On Saturday, October 14, 2023 at 6:01:54 PM UTC+5:30 Dick Visser wrote:
>
>> What is your desired output then??
>>
>> Sent from Gmail Mobile
>>
>>
>> On Sat, 14 Oct 2023 at 10:01, Veera <svee...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I have the below output  from my playbook using
>>> - debug:
>>>         msg: "{{ result.stdout }}"
>>>
>>> TASK [debug]
>>> **************************************************************************************************************************
>>> ok: [localhost] => {
>>>     "msg": {
>>>         "access_token": "xxxxxxxxxx",
>>>         "expires_in": 43200,
>>> "token_type": "xxxxxx"
>>>     }
>>> }
>>>
>>>
>>>  and  when I tried to filter the access token alone  , with map   by
>>> "{{ result.stdout | map('extract', access_token) }}" ., it errors as
>>> below
>>>
>>> The task includes an option with an undefined variable. The error was:
>>> 'access_token' is  undefined\n\n
>>>
>>> and  when I tried to filter the access token alone  , with map   by
>>>  msg: "{{ result.stdout | map(attribute='access_token') }}" ., it
>>> errors as below
>>>
>>> What I am missing here  to get the desired output  here?
>>>
>>>
>>> --
>>> 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 ansible-proje...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/6a7a5ed1-6c6b-4660-8da9-1388898923fen%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/6a7a5ed1-6c6b-4660-8da9-1388898923fen%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/f1f16814-e47b-4251-8bea-9e9660ead1fcn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/f1f16814-e47b-4251-8bea-9e9660ead1fcn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKtKohT3Py2bdQDZUow4o325SZnp0E4gZf1Aqnz2tv%3D3jD%2BL-w%40mail.gmail.com.

Reply via email to