# Register command output with\_items

**URL:** <https://forum.ansible.com/t/register-command-output-with-items/21300>\
**Category:** Ansible Project\
**Created:** [April 28, 2016, 2:15pm UTC](https://forum.ansible.com/t/register-command-output-with-items/21300 "2016-04-28T14:15:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srividhya\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Srividhya\_Mohan](https://forum.ansible.com/u/Srividhya_Mohan)\
**Post date:** [April 28, 2016, 2:15pm UTC](https://forum.ansible.com/t/register-command-output-with-items/21300/1 "2016-04-28T14:15:29Z")

</div>

Hi

I have the following in my playbook

- hosts: localhost  
tasks:

- name: echo output  
command: echo {{item}}  
register: echo\_output  
with\_items:

- hi

- hello

- debug: msg=“{{ echo\_output.results}}”

When I run this playbook, I am getting the following

RES1SMOHANAS-M1:ansible-portal\_platform smohanasundaram$ ansible-playbook -i inventory/sriDev.ini -c local portal\_platform\_liferay\_patches\_prestage.yml  
[WARNING]: The `prettytable` python module is not installed. Disabling the  
HipChat callback plugin.

[WARNING]: HipChat token could not be loaded. The HipChat token can be  
provided using the `HIPCHAT_TOKEN` environment variable.

PLAY [localhost] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

GATHERING FACTS \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1]

TASK: [echo output] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
changed: [127.0.0.1] =\> (item=hi)  
changed: [127.0.0.1] =\> (item=hello)

TASK: [debug msg=“{{ echo\_output.results}}”] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “[{u’stdout’: u’hi’, u’changed’: True, u’end’: u’2016-04-28 10:14:19.487867’, u’start’: u’2016-04-28 10:14:19.465853’, u’cmd’: [u’echo’, u’hi’], u’rc’: 0, ‘item’: ‘hi’, u’stderr’: u’‘, u’delta’: u’0:00:00.022014’, ‘invocation’: {‘module\_name’: u’command’, ‘module\_args’: u’echo hi’}, u’warnings’: }, {u’stdout’: u’hello’, u’changed’: True, u’end’: u’2016-04-28 10:14:19.710345’, u’start’: u’2016-04-28 10:14:19.688217’, u’cmd’: [u’echo’, u’hello’], u’rc’: 0, ‘item’: ‘hello’, u’stderr’: u’‘, u’delta’: u’0:00:00.022128’, ‘invocation’: {‘module\_name’: u’command’, ‘module\_args’: u’echo hello’}, u’warnings’: }]”  
}

TASK: [debug msg=“{{ echo\_output.results|map(attribute=‘stdout’)|list}}”] \*\*\*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “[u’hi’, u’hello’]”  
}

TASK: [debug msg=“{{ echo\_output.results|map(attribute=‘stdout\_lines’)|list}}”] \*\*\*  
ok: [127.0.0.1] =\> {  
“msg”: “[Undefined, Undefined]”  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
127.0.0.1 : ok=5 changed=1 unreachable=0 failed=0

’

Looks like stdout\_lines is not present in the “echo\_output.results”. Please let me know what could be wrong here.

Thanks  
Sri

---

<div class="post-metadata">

**Author:** ![John\_Buxton](https://avatars.discourse-cdn.com/v4/letter/j/7bcc69/32.png) [@John\_Buxton](https://forum.ansible.com/u/John_Buxton)\
**Post date:** [May 1, 2016, 8:57am UTC](https://forum.ansible.com/t/register-command-output-with-items/21300/2 "2016-05-01T08:57:21Z")

</div>

Sri,  
It would help if the your output matched the playbook you are running.

Your problem task isn’t even in your test playbook!

> TASK: [debug msg=“{{ echo\_output.results|map(attribute=‘stdout\_lines’)|list}}”] \*\*\*  
> ok: [127.0.0.1] =\> {  
> “msg”: “[Undefined, Undefined]”  
> }

Anyway, this works for me on stable-2.0.0.1 on centos 7.  
I get the output below, which is probably what you are expecting:

ok: [t1] =\> {  
“msg”: [  
[  
“hi”  
],  
[  
“hello”  
]  
]  
}

---

<div class="post-metadata">

**Author:** ![Srividhya\_Mohan](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Srividhya\_Mohan](https://forum.ansible.com/u/Srividhya_Mohan)\
**Post date:** [May 10, 2016, 12:41am UTC](https://forum.ansible.com/t/register-command-output-with-items/21300/3 "2016-05-10T00:41:02Z")

</div>

Hi John

Do you mind sharing your playbook with me? So that I can take a look at the code.

Thanks  
Sri
