Need help with registered variable

46 views
Skip to first unread message

Rahul Kumar

unread,
Jul 10, 2020, 7:54:37 AM7/10/20
to ansible...@googlegroups.com
I have a task output like this:
- name: Print Response of status resource
  debug:
    msg: " {{ result }}"

ok: [node-3] => {
    "msg": " {'msg': u'All items completed', 'changed': False, 'results': [{'ansible_loop_var': u'item', 'failed': False, 'changed': False, u'content': {u'body': None, u'node': u'node-3', u'allServicesLocked': True, u'appServer': u'1', u'type': u'iMIME', u'data': True,]} "
}

But when i try to access like that in some task, it does not work:
until : result['results'].data == True   , it complains saying dict does not have results attribute !
Here result is my registered variable. As per above response , it should work fine ?


Abhijeet Kasurde

unread,
Jul 10, 2020, 8:02:28 AM7/10/20
to ansible...@googlegroups.com
'data' is inside 'content' you might want to check around that


--
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/CAGH8rEyOHqmrA7diB3AznLqRncRaj_r539gA5-oZpkEwMrzwCA%40mail.gmail.com.


--
Thanks,
Abhijeet Kasurde

Rahul Kumar

unread,
Jul 10, 2020, 10:34:29 AM7/10/20
to ansible...@googlegroups.com
Thanks Abhijeet ! I tried even result[‘results’][0].content.data but still it complains results is not dict attribute ! 

Srinivas Naram

unread,
Jul 10, 2020, 12:42:29 PM7/10/20
to ansible...@googlegroups.com
Try by removing  quotes 

result[results][0].content.data  

Rahul Kumar

unread,
Jul 13, 2020, 6:49:39 AM7/13/20
to ansible...@googlegroups.com
No even it complains  results is not defined !

I am not understanding whats wrong here :
Here is the task:
- name: print boss
  debug:
   msg: " {{ result }}"

and output is:
ok: [node-1] => {
    "msg": " {'msg': u'All items completed', 'changed': False, 'results': [{'ansible_loop_var': u'item', 'failed': False, 'changed': False, u'content': {u'body': None, u'node': u'node-1', u'isFetched': True, u'appServer': u'1', u'type': u'appServerFullStatus', u'allServicesEnabled': 

I need to reach upto isFetched in this json ?

Rahul Kumar

unread,
Jul 13, 2020, 7:14:38 AM7/13/20
to ansible...@googlegroups.com
Notice, result is registered with loop ! So wanted to check in case of loop does registered variable contains result of each iteration ?

Vladimir Botka

unread,
Jul 13, 2020, 10:17:21 AM7/13/20
to Rahul Kumar, ansible...@googlegroups.com
On Fri, 10 Jul 2020 17:24:05 +0530
Rahul Kumar <rajput...@gmail.com> wrote:

> I have a task output like this:
> - name: Print Response of status resource
> debug:
> msg: " {{ result }}"
>
> ok: [node-3] => {
> "msg": " {'msg': u'All items completed', 'changed': False, 'results':
> [{'ansible_loop_var': u'item', 'failed': False, 'changed': False,
> u'content': {u'body': None, u'node': u'node-3', u'allServicesLocked': True,
> u'appServer': u'1', u'type': u'iMIME', u'data': True,]} "
> }

Use "yaml" callback plugin when you want to see complex structures. For
example, this task

- debug:
var: result

would give

shell> ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook test.yml

result:
changed: false
msg: All items completed
results:
- ansible_loop_var: item
changed: false
content:
allServicesLocked: true
appServer: '1'
body: None
data: true
node: node-3
type: iMIME
failed: false

Then, it's easier to find an expression which you're probably looking for

- debug:
var: result.results.0.content.data

HTH,

-vlado
--
Vladimir Botka

Rahul Kumar

unread,
Jul 14, 2020, 8:10:45 AM7/14/20
to Vladimir Botka, ansible...@googlegroups.com
THanks Vlad ! 
I will use same ! 

Regards
Rahul
Reply all
Reply to author
Forward
0 new messages