From 40a1f20bea6ae499acb64ed59625494f24defea6 Mon Sep 17 00:00:00 2001 From: yuriy-z Date: Tue, 21 Mar 2017 22:51:18 +0200 Subject: [PATCH] Add storage device WWN to facts for Linux (#16640) World Wide Name (WWN) is unique identifier of device. This patch adds this identifier to facts for Linux. --- lib/ansible/module_utils/facts.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index fcd423f57e..dcae17d745 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1435,6 +1435,20 @@ class LinuxHardware(Hardware): except OSError: return + devs_wwn = {} + try: + devs_by_id = os.listdir("/dev/disk/by-id") + except OSError: + pass + else: + for link_name in devs_by_id: + if link_name.startswith("wwn-"): + try: + wwn_link = os.readlink(os.path.join("/dev/disk/by-id", link_name)) + except OSError: + continue + devs_wwn[os.path.basename(wwn_link)] = link_name[4:] + for block in block_devs: virtual = 1 sysfs_no_links = 0 @@ -1467,6 +1481,9 @@ class LinuxHardware(Hardware): ]: d[key] = get_file_content(sysdir + test) + if diskname in devs_wwn: + d['wwn'] = devs_wwn[diskname] + d['partitions'] = {} for folder in os.listdir(sysdir): m = re.search("(" + diskname + "\d+)", folder)