# Getting error for ".stdout\_lines" for a registered variable

**URL:** <https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353>\
**Category:** Ansible Project\
**Created:** [September 24, 2019, 5:06pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353 "2019-09-24T17:06:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [September 24, 2019, 5:06pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/1 "2019-09-24T17:06:20Z")

</div>

Hi,

I have playbook to retrieve the Instance id of Openstack nodes.Now everything works fine but the resgitered value for instid.stdout\_lines gets an undefined error.  
**The error was: ‘dict object’ has no attribute ‘stdout\_lines’** … but when i debug the complete registered variable instid i see stdout\_lines. but why its failing when i debug it using instid.stdout\_lines

“item”: “TOMCS2”,  
“rc”: 0,  
“start”: “2019-09-24 09:15:45.801051”,  
“stderr”: “”,  
“stderr\_lines”: ,  
“stdout”: “e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2”,  
**“stdout\_lines”: [**  
**“e8ebc5a4-17f3-4b80-a935-03164211a804 TOMCS2”**

- hosts: nodes[0]  
gather\_facts: false  
tasks:

- name: Collect Hostnames  
set\_fact:  
host\_lists: “{{ hostvars[inventory\_hostname][‘groups’][‘nodes’] }}”

- name: Create Hostname as per the Name in openstack names  
set\_fact:  
fact: ‘{{ ([“TOM”] \* host\_lists|length)|zip(host\_lists)|map(“join”)|list}}’

- name: Debug the required list  
debug:  
msg: “{{ fact }}”

- hosts: 127.0.0.1  
gather\_facts: false  
tasks:

- name: Retrieve tenantID  
shell: openstack project list | awk ‘/ TOM / { print $2 }’  
register: tenantid

- name: Retrieve instance id from tenant  
shell: openstack server list --all-projects --project “{{ tenantid.stdout }}” | awk ‘NR \> 3 { print $2, $4 }’ | grep -i “{{ item }}”  
with\_items: “{{ hostvars[groups[‘nodes’][0]][‘fact’] }}”  
register: instid

- name: Debug Instance id and Tennat id  
delegate\_to: localhost  
debug:  
msg:

- “Tenant ID:”

- “{{ tenantid.stdout }}”

- “===============================”

- "Instance ID of the VMs in TOM

- “{{ instid.stdout\_lines}}”

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 24, 2019, 5:24pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/2 "2019-09-24T17:24:36Z")

</div>

What is the _complete_ output from a debug of instid?

Regards, K.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 24, 2019, 5:34pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/3 "2019-09-24T17:34:54Z")

</div>

When using register with with\_items/loop you'll have instid.results which is a list where each item contain the output for each command.

When you get errors like this always run a  
&nbsp;&nbsp;- debug: var=instid

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [September 24, 2019, 5:37pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/4 "2019-09-24T17:37:28Z")

</div>

There are 11 items , i will paste the out put of one item, all others are similar, or this mail will be lengthy. SO pasting the out put of one item.

“\_ansible\_delegated\_vars”: {  
“ansible\_delegated\_host”: “localhost”,  
“ansible\_host”: “localhost”  
},  
“\_ansible\_ignore\_errors”: null,  
“\_ansible\_item\_label”: “TOMICS2”,  
“\_ansible\_item\_result”: true,  
“\_ansible\_no\_log”: false,  
“\_ansible\_parsed”: true,  
“changed”: true,  
“cmd”: “openstack server list --all-projects --project "ca257bcbf01745aba61edd9699cd4902" | awk ‘NR \> 3 { print $2, $4 }’ | grep -i "TOMICS2"”,  
“delta”: “0:00:02.312475”,  
“end”: “2019-09-24 09:15:48.113526”,  
“failed”: false,  
“invocation”: {  
“module\_args”: {  
“\_raw\_params”: “openstack server list --all-projects --project "ca257bcbf01745aba61edd9699cd4902" | awk ‘NR \> 3 { print $2, $4 }’ | grep -i "TOMICS2"”,  
“\_uses\_shell”: true,  
“argv”: null,  
“chdir”: null,  
“creates”: null,  
“executable”: null,  
“removes”: null,  
“stdin”: null,  
“warn”: true  
}  
},  
“item”: “TOMICS2”,  
“rc”: 0,  
“start”: “2019-09-24 09:15:45.801051”,  
“stderr”: “”,  
“stderr\_lines”: ,  
“stdout”: “e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2”,  
**“stdout\_lines”: [**  
**“e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2”**  
]  
},

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [September 24, 2019, 5:48pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/5 "2019-09-24T17:48:29Z")

</div>

Hi Kai,

I had already tried it it gives me o/p as same as :  
debug:  
msg: {{ instid }}

Both the o/ps are similar.

Now i want the stdout\_lines for each item as my desired o/p  
something like:  
e8ebc5a4-17f3-4b80-a935-03164211a804 TOMICS2  
7865dvgsf-17f3-4b80-a935-03164211a804 TOMICS1  
abc12345g-17f3-4b80-a935-03164211a804 TOMIAS2

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [September 24, 2019, 5:57pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/6 "2019-09-24T17:57:59Z")

</div>

As I wrote instid contains a results which is a list so you need to loop over it to get the individual results.

- debug: msg="{{ item.stdout }}"  
&nbsp;&nbsp;with\_items: "{{ instid.results }}"

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 24, 2019, 6:02pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/7 "2019-09-24T18:02:53Z")

</div>

Post the _complete_ output of

- debug:  
var: instid

Posting snippets is useless.

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [September 24, 2019, 7:42pm UTC](https://forum.ansible.com/t/getting-error-for-stdout-lines-for-a-registered-variable/31353/8 "2019-09-24T19:42:19Z")

</div>

Hi Kai,

I could do achieve what i intended. I made the following changes using Jinja format and my issue solved.  
Thanks for the help. Th echanges i made was:  
In the Instance id section i used the foloing formula and it worked like a charm.

- name: Set fact for Instance id from Tenant ID  
delegate\_to: localhost  
set\_fact:  
id\_list: “{% for item in instid.results %}  
{{ item.stdout\_lines[0].split()[0] }}  
{% endfor %}”

- name: Set fact for Desired Instance ids  
set\_fact:  
desired\_instid: “{{ id\_list.split() }}”
