Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
Thanks Vladimir .. rich info for me ..

On Saturday, October 14, 2023 at 8:58:23 PM UTC+5:30 Vladimir Botka wrote:

> On Sat, 14 Oct 2023 01:01:28 -0700 (PDT)
> Veera  wrote:
>
> > - debug:
> > msg: "{{ result.stdout }}"
> > 
> > ok: [localhost] => {
> > "msg": {
> > "access_token": "xx",
> > "expires_in": 43200,
> > "token_type": "xx"
> > }
> > }
>
> For example, given the file
>
> shell> cat /tmp/test.json 
> {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
>
> The value of *result.stdout* is *AnsibleUnsafeText*. What you see
> depends on the callback. The below play
>
> shell> cat pb.yml
> - hosts: all
> tasks:
> - command: cat /tmp/test.json
> register: result
> - debug:
> var: result.stdout
>
> gives JSON with the default callback
>
> shell> ANSIBLE_STDOUT_CALLBACK=default ansible-playbook pb.yml
> ...
> ok: [localhost] => {
> "result.stdout": {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
> }
>
> The same task gives YAML with the yaml callback
>
> shell> ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook pb2.yml
> ...
> ok: [localhost] => 
> result.stdout:
> access_token: xx
> expires_in: 43200
> token_type: xx
>
> You can test the type of the attribute *stdout*
>
> - debug:
> var: result.stdout|type_debug
>
> gives
>
> result.stdout|type_debug: AnsibleUnsafeText
>
>
> > filter the access token alone
>
> Convert the text to dictionary and get the *access_token* as well.
> It's up to you where you put the vars
>
> vars:
>
> test_data: "{{ result.stdout|from_json }}"
> access_token: "{{ test_data.access_token }}"
>
> Example of a complete playbook for testing
>
> shell> cat pb.yml
> - hosts: all
>
> vars:
>
> test_data: "{{ result.stdout|from_json }}"
> access_token: "{{ test_data.access_token }}"
>
> tasks:
>
> - command: cat /tmp/test.json
> register: result
> - debug:
> var: result.stdout
> - debug:
> var: result.stdout|type_debug
> - debug:
> var: test_data|type_debug
> - debug:
> var: test_data
> - debug:
> var: access_token
>
>
> -- 
> Vladimir Botka
>

-- 
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/10c295f5-79bd-49ee-84dd-76944f6a2bb5n%40googlegroups.com.


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Vladimir Botka
On Sat, 14 Oct 2023 01:01:28 -0700 (PDT)
Veera  wrote:

> - debug:
> msg: "{{ result.stdout }}"
> 
> ok: [localhost] => {
> "msg": {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
> }

For example, given the file

shell> cat /tmp/test.json 
{
"access_token": "xx",
"expires_in": 43200,
"token_type": "xx"
}

The value of *result.stdout* is *AnsibleUnsafeText*. What you see
depends on the callback. The below play

shell> cat pb.yml
- hosts: all
  tasks:
- command: cat /tmp/test.json
  register: result
- debug:
var: result.stdout

gives JSON with the default callback

shell> ANSIBLE_STDOUT_CALLBACK=default ansible-playbook pb.yml
  ...
ok: [localhost] => {
"result.stdout": {
"access_token": "xx",
"expires_in": 43200,
"token_type": "xx"
}
}

The same task gives YAML with the yaml callback

shell> ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook pb2.yml
  ...
ok: [localhost] => 
  result.stdout:
access_token: xx
expires_in: 43200
token_type: xx

You can test the type of the attribute *stdout*

- debug:
var: result.stdout|type_debug

gives

  result.stdout|type_debug: AnsibleUnsafeText


>  filter the access token alone

Convert the text to dictionary and get the *access_token* as well.
It's up to you where you put the vars

  vars:

test_data: "{{ result.stdout|from_json }}"
access_token: "{{ test_data.access_token }}"

Example of a complete playbook for testing

shell> cat pb.yml
- hosts: all

  vars:

test_data: "{{ result.stdout|from_json }}"
access_token: "{{ test_data.access_token }}"

  tasks:

- command: cat /tmp/test.json
  register: result
- debug:
var: result.stdout
- debug:
var: result.stdout|type_debug
- debug:
var: test_data|type_debug
- debug:
var: test_data
- debug:
var: access_token


-- 
Vladimir Botka

-- 
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/20231014172804.3f085226%40gmail.com.


pgpJQrJn3h_61.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
It worked and its my miss again to combine it ..  :)

On Saturday, October 14, 2023 at 8:36:11 PM UTC+5:30 Dick Visser wrote:

> Yes, so you should combine them like:
>
>   - debug:
>   msg: "{{ (result.stdout|from_json).access_token }}"
>
>
>
> On Sat, 14 Oct 2023 at 16:10, Veera  wrote:
>
>>
>> when I try with 
>>  - debug:
>>msg: "{{ result }}"
>>
>> the output is 
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "changed": true,
>> "cmd": "curl -X POST 'https://xx.com/auth/login' -H 
>> 'Content-Type: application/json' -d @.mycred.json",
>> -- trimmed lines 
>> "rc": 0,
>>-- trimmed lines 
>> "stdout": 
>> "{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
>> "stdout_lines": [
>> 
>> "{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
>> ]
>> }
>> }
>>
>>
>> The output for the 
>>   - debug:
>>   msg: "{{ result.stdout |from_json  }}"
>>
>> is
>>
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "access_token": "XX",
>> "expires_in": 86400,
>> "token_type": "Bearer"
>> }
>> }
>>
>>
>>
>> when I use  the 
>>  - debug:
>>  msg: "{{ result.stdout.access_token }}"
>>
>> the error is 
>>
>> TASK [debug] 
>> **
>> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with 
>> an undefined variable. The error was: 
>> 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
>> 'access_token'\n\nThe error appears to be in '/home/user/check.yml': line 
>> 32, column 7, but may\nbe elsewhere in the file depending on the exact 
>> syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n   
>>^ here\n"}
>>
>> On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:
>>
>>> 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: xx
>>> expires_in: 4320
>>> token_type: yy
>>>
>>>   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": "xx",
>>> "expires_in": 4320,
>>> "token_type": "yy"
>>> }
>>> }
>>> }
>>>
>>> TASK [extract the token] 
>>> ***
>>> ok: [localhost] => {
>>> "msg": "xx"
>>> }
>>>
>>>
>>> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>>>
 I need only the output or the value of the below(trying to set_fact the 
 access_token)
 access_token": "xx"




 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  wrote:
>
>> Hi,
>>
>> I have the below output  from my playbook using 
>> - debug:
>> msg: "{{ result.stdout }}"
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "access_token": "xx",
>> "expires_in": 43200,
>> "token_type": "xx"
>> }
>> }
>>
>>
>>  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 

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Dick Visser
Yes, so you should combine them like:

  - debug:
  msg: "{{ (result.stdout|from_json).access_token }}"



On Sat, 14 Oct 2023 at 16:10, Veera  wrote:

>
> when I try with
>  - debug:
>msg: "{{ result }}"
>
> the output is
>
> TASK [debug]
> **
> ok: [localhost] => {
> "msg": {
> "changed": true,
> "cmd": "curl -X POST 'https://xx.com/auth/login' -H
> 'Content-Type: application/json' -d @.mycred.json",
> -- trimmed lines 
> "rc": 0,
>-- trimmed lines 
> "stdout":
> "{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
> "stdout_lines": [
>
> "{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
> ]
> }
> }
>
>
> The output for the
>   - debug:
>   msg: "{{ result.stdout |from_json  }}"
>
> is
>
>
> TASK [debug]
> **
> ok: [localhost] => {
> "msg": {
> "access_token": "XX",
> "expires_in": 86400,
> "token_type": "Bearer"
> }
> }
>
>
>
> when I use  the
>  - debug:
>  msg: "{{ result.stdout.access_token }}"
>
> the error is
>
> TASK [debug]
> **
> fatal: [localhost]: FAILED! => {"msg": "The task includes an option with
> an undefined variable. The error was:
> 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute
> 'access_token'\n\nThe error appears to be in '/home/user/check.yml': line
> 32, column 7, but may\nbe elsewhere in the file depending on the exact
> syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n
>^ here\n"}
>
> On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:
>
>> 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: xx
>> expires_in: 4320
>> token_type: yy
>>
>>   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": "xx",
>> "expires_in": 4320,
>> "token_type": "yy"
>> }
>> }
>> }
>>
>> TASK [extract the token]
>> ***
>> ok: [localhost] => {
>> "msg": "xx"
>> }
>>
>>
>> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>>
>>> I need only the output or the value of the below(trying to set_fact the
>>> access_token)
>>> access_token": "xx"
>>>
>>>
>>>
>>>
>>> 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  wrote:

> Hi,
>
> I have the below output  from my playbook using
> - debug:
> msg: "{{ result.stdout }}"
>
> TASK [debug]
> **
> ok: [localhost] => {
> "msg": {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
> }
>
>
>  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
> 

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera

when I try with 
 - debug:
   msg: "{{ result }}"

the output is 

TASK [debug] 
**
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "curl -X POST 'https://xx.com/auth/login' -H 
'Content-Type: application/json' -d @.mycred.json",
-- trimmed lines 
"rc": 0,
   -- trimmed lines 
"stdout": 
"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
"stdout_lines": [

"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
]
}
}


The output for the 
  - debug:
  msg: "{{ result.stdout |from_json  }}"

is


TASK [debug] 
**
ok: [localhost] => {
"msg": {
"access_token": "XX",
"expires_in": 86400,
"token_type": "Bearer"
}
}



when I use  the 
 - debug:
 msg: "{{ result.stdout.access_token }}"

the error is 

TASK [debug] 
**
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
'access_token'\n\nThe error appears to be in '/home/user/check.yml': line 
32, column 7, but may\nbe elsewhere in the file depending on the exact 
syntax problem.\n\nThe offending line appears to be:\n\n\n- debug:\n   
   ^ here\n"}

On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:

> 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: xx
> expires_in: 4320
> token_type: yy
>
>   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": "xx",
> "expires_in": 4320,
> "token_type": "yy"
> }
> }
> }
>
> TASK [extract the token] 
> ***
> ok: [localhost] => {
> "msg": "xx"
> }
>
>
> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>
>> I need only the output or the value of the below(trying to set_fact the 
>> access_token)
>> access_token": "xx"
>>
>>
>>
>>
>> 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  wrote:
>>>
 Hi,

 I have the below output  from my playbook using 
 - debug:
 msg: "{{ result.stdout }}"

 TASK [debug] 
 **
 ok: [localhost] => {
 "msg": {
 "access_token": "xx",
 "expires_in": 43200,
 "token_type": "xx"
 }
 }


  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
  
 
 .

>>> -- 
>> You received this message because you are subscribed to the 

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera

when I try with 
 - debug:
 msg: "{{ result }}"


TASK [debug] 
**
ok: [localhost] => {
"msg": {
"changed": true,
"cmd": "curl -X POST 'https://xxx.com/auth/login' -H 
'Content-Type: application/json' -d @.mycred.json",
-- trimmed lines 
"rc": 0,
   -- trimmed lines 
"stdout": 
"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
"stdout_lines": [

"{\"access_token\":\"X\",\"token_type\":\"Bearer\",\"expires_in\":86400}"
]
}
}


The output for the 
  - debug:
  msg: "{{ result.stdout |from_json  }}"

is


TASK [debug] 
**
ok: [localhost] => {
"msg": {
"access_token": "X",
"expires_in": 86400,
"token_type": "Bearer"
}
}



when I use  the 
 - debug:
 msg: "{{ result.stdout.access_token }}"

the error is 

TASK [debug] 
**
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an 
undefined variable. The error was: 
'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 
'access_token'\n\nThe error appears to be in 
'/home/user/nvs/check_vault.yml': line 32, column 7, but may\nbe elsewhere 
in the file depending on the exact syntax problem.\n\nThe offending line 
appears to be:\n\n\n- debug:\n  ^ here\n"}

On Saturday, October 14, 2023 at 6:31:49 PM UTC+5:30 Will McDonald wrote:

> 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: xx
> expires_in: 4320
> token_type: yy
>
>   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": "xx",
> "expires_in": 4320,
> "token_type": "yy"
> }
> }
> }
>
> TASK [extract the token] 
> ***
> ok: [localhost] => {
> "msg": "xx"
> }
>
>
> On Sat, 14 Oct 2023 at 13:43, Veera  wrote:
>
>> I need only the output or the value of the below(trying to set_fact the 
>> access_token)
>> access_token": "xx"
>>
>>
>>
>>
>> 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  wrote:
>>>
 Hi,

 I have the below output  from my playbook using 
 - debug:
 msg: "{{ result.stdout }}"

 TASK [debug] 
 **
 ok: [localhost] => {
 "msg": {
 "access_token": "xx",
 "expires_in": 43200,
 "token_type": "xx"
 }
 }


  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
  
 
 .

>>> -- 
>> You received this message because you are subscribed to the 

Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Will McDonald
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: xx
expires_in: 4320
token_type: yy

  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": "xx",
"expires_in": 4320,
"token_type": "yy"
}
}
}

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


On Sat, 14 Oct 2023 at 13:43, Veera  wrote:

> I need only the output or the value of the below(trying to set_fact the
> access_token)
> access_token": "xx"
>
>
>
>
> 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  wrote:
>>
>>> Hi,
>>>
>>> I have the below output  from my playbook using
>>> - debug:
>>> msg: "{{ result.stdout }}"
>>>
>>> TASK [debug]
>>> **
>>> ok: [localhost] => {
>>> "msg": {
>>> "access_token": "xx",
>>> "expires_in": 43200,
>>> "token_type": "xx"
>>> }
>>> }
>>>
>>>
>>>  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
>>> 
>>> .
>>>
>> --
> 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
> 
> .
>

-- 
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.


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Dick Visser
Try piping it through from_json first

Sent from Gmail Mobile


On Sat, 14 Oct 2023 at 14:43, Veera  wrote:

> I need only the output or the value of the below(trying to set_fact the
> access_token)
> access_token": "xx"
>
>
>
>
> 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  wrote:
>>
>>> Hi,
>>>
>>> I have the below output  from my playbook using
>>> - debug:
>>> msg: "{{ result.stdout }}"
>>>
>>> TASK [debug]
>>> **
>>> ok: [localhost] => {
>>> "msg": {
>>> "access_token": "xx",
>>> "expires_in": 43200,
>>> "token_type": "xx"
>>> }
>>> }
>>>
>>>
>>>  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
>>> 
>>> .
>>>
>> --
> 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
> 
> .
>

-- 
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/CAF8BbLaTXDW2Mgkbr5fjZNk4-gpwJq7s0S93VpRhu%2Bfm7ajPvQ%40mail.gmail.com.


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
I need only the output or the value of the below(trying to set_fact the 
access_token)
access_token": "xx"




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  wrote:
>
>> Hi,
>>
>> I have the below output  from my playbook using 
>> - debug:
>> msg: "{{ result.stdout }}"
>>
>> TASK [debug] 
>> **
>> ok: [localhost] => {
>> "msg": {
>> "access_token": "xx",
>> "expires_in": 43200,
>> "token_type": "xx"
>> }
>> }
>>
>>
>>  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
>>  
>> 
>> .
>>
>

-- 
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.


Re: [ansible-project] Formatting the dict items with debug

2023-10-14 Thread Dick Visser
What is your desired output then??

Sent from Gmail Mobile


On Sat, 14 Oct 2023 at 10:01, Veera  wrote:

> Hi,
>
> I have the below output  from my playbook using
> - debug:
> msg: "{{ result.stdout }}"
>
> TASK [debug]
> **
> ok: [localhost] => {
> "msg": {
> "access_token": "xx",
> "expires_in": 43200,
> "token_type": "xx"
> }
> }
>
>
>  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-project+unsubscr...@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
> 
> .
>

-- 
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/CAF8BbLZSAcb3PKm%3DQQp-GdmGncMKbsxQx8uK2YuJOak%3D7vj1Zw%40mail.gmail.com.


[ansible-project] Formatting the dict items with debug

2023-10-14 Thread Veera
Hi,

I have the below output  from my playbook using 
- debug:
msg: "{{ result.stdout }}"

TASK [debug] 
**
ok: [localhost] => {
"msg": {
"access_token": "xx",
"expires_in": 43200,
"token_type": "xx"
}
}


 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-project+unsubscr...@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.