# access to register stdout\_lines attributes

**URL:** <https://forum.ansible.com/t/access-to-register-stdout-lines-attributes/27532>\
**Category:** Ansible Project\
**Created:** [May 15, 2018, 1:15pm UTC](https://forum.ansible.com/t/access-to-register-stdout-lines-attributes/27532 "2018-05-15T13:15:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deewon](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@deewon](https://forum.ansible.com/u/deewon)\
**Post date:** [May 15, 2018, 1:15pm UTC](https://forum.ansible.com/t/access-to-register-stdout-lines-attributes/27532/1 "2018-05-15T13:15:57Z")

</div>

Hi,

I have a task that executes a shell command and spews out a few lines. Specifically, it probes a remote DB and and returns some information . Please see below:

`

- name: Test role delegation to apps  
hosts: appboxes  
tasks:

- name: get cluster status from dbboxes  
shell: mysqlsh --redirect-primary test123:test123@box1:3306 --cluster -e “cluster.status().defaultReplicaSet.primary” --interactive --json  
register: res  
delegate\_to: “{{ groups.mysqldbs | first }}”  
run\_once: True

- name: check result  
debug:  
var=res.stdout\_lines  
run\_once: True

# - name: check result

# debug:

# var: “{{ item.value }}”

# with\_items: “{{ res.stdout\_lines }}”

# run\_one: True

`

`  
root@controller:/etc/ansible/playbooks# ansible-playbook test\_delegate.yml

PLAY [Test role delegation to apps] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\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*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [appbox1] =\> {  
“res.stdout\_lines”: [  
“{”,  
" "info": "Creating a session to ‘test123@box1:3306’"“,  
“}”,  
“{”,  
" "info": "Your MySQL connection id is 246 Server version: 5.7.21-log MySQL Commercial Server (Advanced) No default schema selected; type \\use to set one."”,  
“}”,  
“{”,  
" "info": "Reconnecting to PRIMARY instance of the InnoDB cluster (mysql://box1:3306)…"“,  
“}”,  
“{”,  
" "info": "Creating a Classic session to ‘test123@box1:3306’"”,  
“}”,  
“{”,  
" "info": "Closing old connection…"“,  
“}”,  
“{”,  
" "info": "Your MySQL connection id is 239 Server version: 5.7.21-log MySQL Commercial Server (Advanced) No default schema selected; type \\use to set one."”,  
“}”,  
“{”,  
" "value": "box1:3306"",  
“}”  
]  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
appbox1 : ok=3 changed=1 unreachable=0 failed=0  
appbox2 : ok=1 changed=0 unreachable=0 failed=0  
`

I’ve been scratching my head trying to figure out how to return only the “value” attribute and its corresponding result.

I tried using a loop (commented out in the playbook) but it just spews out a load of errors saying the attribute doesn’t exist i.e.

`  
TASK [check result] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [appbox1]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘value’\n\nThe error appears to have been in ‘/etc/ansible/playbooks/test\_delegate.yml’: line 15, 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 - name: check result\n ^ here\n\nexception type: \<class ‘ansible.errors.AnsibleUndefinedVariable’\>\nexception: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘value’”}  
fatal: [appbox2]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘value’\n\nThe error appears to have been in ‘/etc/ansible/playbooks/test\_delegate.yml’: line 15, 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 - name: check result\n ^ here\n\nexception type: \<class ‘ansible.errors.AnsibleUndefinedVariable’\>\nexception: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘value’”}  
to retry, use: --limit @/etc/ansible/playbooks/test\_delegate.retry

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
appbox1 : ok=3 changed=1 unreachable=0 failed=1  
appbox2 : ok=1 changed=0 unreachable=0 failed=1  
`

Any ideas will be appreciated  
Dayo

---

<div class="post-metadata">

**Author:** ![deewon](https://avatars.discourse-cdn.com/v4/letter/d/ecb155/32.png) [@deewon](https://forum.ansible.com/u/deewon)\
**Post date:** [May 18, 2018, 9:05am UTC](https://forum.ansible.com/t/access-to-register-stdout-lines-attributes/27532/2 "2018-05-18T09:05:40Z")

</div>

Got to the bottom of this eventually…

-debug: var= “{{ res.stdout\_lines | last }}”

It’s the last item in the list
