get stdout from a registered variable

48 views
Skip to first unread message

Yariv Graf

unread,
May 7, 2015, 5:01:16 AM5/7/15
to ansible...@googlegroups.com
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.

Brian Coca

unread,
May 7, 2015, 10:24:00 AM5/7/15
to ansible...@googlegroups.com
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

--
Brian Coca

Yariv Graf

unread,
May 7, 2015, 10:36:01 AM5/7/15
to ansible...@googlegroups.com
Thank you


--
Brian Coca

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/mxPBOF-zokc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAJ5XC8mdNW6r0X4Cv%3DGtkacQMgHKK_ELWztXfoYWch-mXx%2B0eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
-Yariv
Reply all
Reply to author
Forward
0 new messages