# Need help with registered variable

**URL:** <https://forum.ansible.com/t/need-help-with-registered-variable/33367>\
**Category:** Ansible Project\
**Created:** [July 10, 2020, 11:54am UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367 "2020-07-10T11:54:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [July 10, 2020, 11:54am UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/1 "2020-07-10T11:54:05Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [July 10, 2020, 12:01pm UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/2 "2020-07-10T12:01:51Z")

</div>

‘data’ is inside ‘content’ you might want to check around that

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [July 10, 2020, 2:32pm UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/3 "2020-07-10T14:32:28Z")

</div>

Thanks Abhijeet ! I tried even result[‘results’][0].content.data but still it complains results is not dict attribute !

---

<div class="post-metadata">

**Author:** ![Srinivas\_Naram](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@Srinivas\_Naram](https://forum.ansible.com/u/Srinivas_Naram)\
**Post date:** [July 10, 2020, 4:42pm UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/4 "2020-07-10T16:42:04Z")

</div>

Try by removing quotes

result[results][0].content.data

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [July 13, 2020, 10:49am UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/5 "2020-07-13T10:49:07Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [July 13, 2020, 11:13am UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/6 "2020-07-13T11:13:51Z")

</div>

Notice, result is registered with loop ! So wanted to check in case of loop does registered variable contains result of each iteration ?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [July 13, 2020, 2:17pm UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/7 "2020-07-13T14:17:01Z")

</div>

> I have a task output like this:  
> - name: Print Response of status resource  
> &nbsp;&nbsp;debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;msg: " {{ result }}"
> 
> ok: [node-3] =\> {  
> &nbsp;&nbsp;&nbsp;&nbsp;"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

&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: result

would give

&nbsp;&nbsp;\> ANSIBLE\_STDOUT\_CALLBACK=yaml ansible-playbook test.yml

&nbsp;&nbsp;result:  
&nbsp;&nbsp;&nbsp;&nbsp;changed: false  
&nbsp;&nbsp;&nbsp;&nbsp;msg: All items completed  
&nbsp;&nbsp;&nbsp;&nbsp;results:  
&nbsp;&nbsp;&nbsp;&nbsp;- ansible\_loop\_var: item  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;changed: false  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;allServicesLocked: true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;appServer: '1'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;body: None  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data: true  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;node: node-3  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: iMIME  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;failed: false

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

&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: result.results.0.content.data

HTH,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Rahul\_Kumar1](https://avatars.discourse-cdn.com/v4/letter/r/da6949/32.png) [@Rahul\_Kumar1](https://forum.ansible.com/u/Rahul_Kumar1)\
**Post date:** [July 14, 2020, 12:10pm UTC](https://forum.ansible.com/t/need-help-with-registered-variable/33367/8 "2020-07-14T12:10:13Z")

</div>

THanks Vlad !  
I will use same !

Regards  
Rahul
