Register command output with_items

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

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”
]
]
}

Hi John

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

Thanks
Sri