From 4b5203c5fb00ede6790bf48fac1d926e9b626bf4 Mon Sep 17 00:00:00 2001 From: Lars Fredriksen Date: Tue, 28 Jun 2016 08:44:51 -0500 Subject: [PATCH] add holders to partitions (#16446) * add holders to partitions * make holder gathering a function --- lib/ansible/module_utils/facts.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 3f195a9a04f..2f4d30c875f 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1249,6 +1249,18 @@ class LinuxHardware(Hardware): 'uuid': uuid, }) + def get_holders(self, block_dev_dict, sysdir): + block_dev_dict['holders'] = [] + if os.path.isdir(sysdir + "/holders"): + for folder in os.listdir(sysdir + "/holders"): + if not folder.startswith("dm-"): + continue + name = get_file_content(sysdir + "/holders/" + folder + "/dm/name") + if name: + block_dev_dict['holders'].append(name) + else: + block_dev_dict['holders'].append(folder) + def get_device_facts(self): self.facts['devices'] = {} lspci = self.module.get_bin_path('lspci') @@ -1308,6 +1320,8 @@ class LinuxHardware(Hardware): if not part['sectorsize']: part['sectorsize'] = get_file_content(part_sysdir + "/queue/hw_sector_size",512) part['size'] = self.module.pretty_bytes((float(part['sectors']) * float(part['sectorsize']))) + self.get_holders(part, part_sysdir) + d['partitions'][partname] = part d['rotational'] = get_file_content(sysdir + "/queue/rotational") @@ -1337,16 +1351,7 @@ class LinuxHardware(Hardware): if m: d['host'] = m.group(1) - d['holders'] = [] - if os.path.isdir(sysdir + "/holders"): - for folder in os.listdir(sysdir + "/holders"): - if not folder.startswith("dm-"): - continue - name = get_file_content(sysdir + "/holders/" + folder + "/dm/name") - if name: - d['holders'].append(name) - else: - d['holders'].append(folder) + self.get_holders(d, sysdir) self.facts['devices'][diskname] = d