mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix bug where ansible_lvm facts silently fails if a PV isn't in an VG (#28684)
If a PV hasn't been added to a VG i.e.: [pmcclory@box ~]$ sudo pvs --noheadings --nosuffix --units g /dev/xvdb lvm2 ---- 10.00 10.00 /dev/xvdv1 vg0 lvm2 a--u 24.99 0 Than ansible_facts.ansible_lvm will be unset after running setup module. The issue is that the module splits on whitespace, which causes an indexing error when the VG column is empty. Fix is to add the separator field and safely split on that.
This commit is contained in:
parent
c1be5b2389
commit
5065bf169d
1 changed files with 4 additions and 4 deletions
|
@ -663,7 +663,7 @@ class LinuxHardware(Hardware):
|
||||||
lvm_facts = {}
|
lvm_facts = {}
|
||||||
|
|
||||||
if os.getuid() == 0 and self.module.get_bin_path('vgs'):
|
if os.getuid() == 0 and self.module.get_bin_path('vgs'):
|
||||||
lvm_util_options = '--noheadings --nosuffix --units g'
|
lvm_util_options = '--noheadings --nosuffix --units g --separator ,'
|
||||||
|
|
||||||
vgs_path = self.module.get_bin_path('vgs')
|
vgs_path = self.module.get_bin_path('vgs')
|
||||||
# vgs fields: VG #PV #LV #SN Attr VSize VFree
|
# vgs fields: VG #PV #LV #SN Attr VSize VFree
|
||||||
|
@ -671,7 +671,7 @@ class LinuxHardware(Hardware):
|
||||||
if vgs_path:
|
if vgs_path:
|
||||||
rc, vg_lines, err = self.module.run_command('%s %s' % (vgs_path, lvm_util_options))
|
rc, vg_lines, err = self.module.run_command('%s %s' % (vgs_path, lvm_util_options))
|
||||||
for vg_line in vg_lines.splitlines():
|
for vg_line in vg_lines.splitlines():
|
||||||
items = vg_line.split()
|
items = vg_line.split(',')
|
||||||
vgs[items[0]] = {'size_g': items[-2],
|
vgs[items[0]] = {'size_g': items[-2],
|
||||||
'free_g': items[-1],
|
'free_g': items[-1],
|
||||||
'num_lvs': items[2],
|
'num_lvs': items[2],
|
||||||
|
@ -684,7 +684,7 @@ class LinuxHardware(Hardware):
|
||||||
if lvs_path:
|
if lvs_path:
|
||||||
rc, lv_lines, err = self.module.run_command('%s %s' % (lvs_path, lvm_util_options))
|
rc, lv_lines, err = self.module.run_command('%s %s' % (lvs_path, lvm_util_options))
|
||||||
for lv_line in lv_lines.splitlines():
|
for lv_line in lv_lines.splitlines():
|
||||||
items = lv_line.split()
|
items = lv_line.split(',')
|
||||||
lvs[items[0]] = {'size_g': items[3], 'vg': items[1]}
|
lvs[items[0]] = {'size_g': items[3], 'vg': items[1]}
|
||||||
|
|
||||||
pvs_path = self.module.get_bin_path('pvs')
|
pvs_path = self.module.get_bin_path('pvs')
|
||||||
|
@ -693,7 +693,7 @@ class LinuxHardware(Hardware):
|
||||||
if pvs_path:
|
if pvs_path:
|
||||||
rc, pv_lines, err = self.module.run_command('%s %s' % (pvs_path, lvm_util_options))
|
rc, pv_lines, err = self.module.run_command('%s %s' % (pvs_path, lvm_util_options))
|
||||||
for pv_line in pv_lines.splitlines():
|
for pv_line in pv_lines.splitlines():
|
||||||
items = pv_line.split()
|
items = pv_line.split(',')
|
||||||
pvs[self._find_mapper_device_name(items[0])] = {
|
pvs[self._find_mapper_device_name(items[0])] = {
|
||||||
'size_g': items[4],
|
'size_g': items[4],
|
||||||
'free_g': items[5],
|
'free_g': items[5],
|
||||||
|
|
Loading…
Reference in a new issue