From 4b9b0a25c3a0c50ae95af55c91ccd4ef322cfb62 Mon Sep 17 00:00:00 2001 From: Alexander Gordeev Date: Fri, 24 Mar 2017 20:13:33 +0400 Subject: [PATCH] Add pvs info to linux hardware 'ansible_lvm' facts (#16773) This change adds the information about physical volume to hardware facts. --- lib/ansible/module_utils/facts.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index ca4c5894fc..a9e61d80be 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -1553,6 +1553,17 @@ class LinuxHardware(Hardware): uptime_seconds_string = uptime_file_content.split(' ')[0] self.facts['uptime_seconds'] = int(float(uptime_seconds_string)) + def _find_mapper_device_name(self, dm_device): + dm_prefix = '/dev/dm-' + mapper_device = dm_device + if dm_device.startswith(dm_prefix): + dmsetup_cmd = self.module.get_bin_path('dmsetup', True) + mapper_prefix = '/dev/mapper/' + rc, dm_name, err = self.module.run_command("%s info -C --noheadings -o name %s" % (dmsetup_cmd, dm_device)) + if rc == 0: + mapper_device = mapper_prefix + dm_name.rstrip() + return mapper_device + def get_lvm_facts(self): """ Get LVM Facts if running as root and lvm utils are available """ @@ -1581,7 +1592,20 @@ class LinuxHardware(Hardware): items = lv_line.split() lvs[items[0]] = {'size_g': items[3], 'vg': items[1]} - self.facts['lvm'] = {'lvs': lvs, 'vgs': vgs} + + pvs_path = self.module.get_bin_path('pvs') + #pvs fields: PV VG #Fmt #Attr PSize PFree + pvs = {} + if pvs_path: + rc, pv_lines, err = self.module.run_command( '%s %s' % (pvs_path, lvm_util_options)) + for pv_line in pv_lines.splitlines(): + items = pv_line.split() + pvs[self._find_mapper_device_name(items[0])] = { + 'size_g': items[4], + 'free_g': items[5], + 'vg': items[1]} + + self.facts['lvm'] = {'lvs': lvs, 'vgs': vgs, 'pvs': pvs} class SunOSHardware(Hardware):