get stdout from a registered variable

Hi,
I have this piece of yaml playbook:

  • name: get read block device such /dev/sdX
    shell: “readlink -f /dev/disk/by-id/google-{{ item.block }}”
    with_items: mounts
    register: device

  • debug: var=device.results

Trying to get the read “sd” device from a symlink.

the output of device.results is:

ok: [ygtest] => {
“var”: {
“device.results”: [
{
“changed”: true,
“cmd”: “readlink -f /dev/disk/by-id/google-local-ssd-0”,
“delta”: “0:00:00.003578”,
“end”: “2015-05-07 08:56:24.201753”,
“invocation”: {
“module_args”: “readlink -f /dev/disk/by-id/google-local-ssd-0”,
“module_name”: “shell”
},
“item”: {
“block”: “local-ssd-0”
},
“rc”: 0,
“start”: “2015-05-07 08:56:24.198175”,
“stderr”: “”,
“stdout”: “/dev/sdb”,
“stdout_lines”: [
“/dev/sdb”
],
“warnings”:
}
]
}
}

How can I access the “stdout” value? I need the output of “/dev/sdb”

Thanks.

the issue is that with_items always creates a result list, so you can
access stdout of each item this way:

device.results[i].stdout

where i is the 0 based index of items, since you seem to have only 1
mount this will be what you need:

device.results[0].stdout

Thank you