facts: fix device uuid's on el6 (#36128)

* facts: fix device uuid's on el6

Fixes #36077
This commit is contained in:
Martin Krizek 2018-02-16 16:52:51 +01:00 committed by Adrian Likins
commit 3a5263a92f
4 changed files with 70 additions and 4 deletions

View file

@ -372,6 +372,31 @@ class LinuxHardware(Hardware):
return uuids
def _udevadm_uuid(self, device):
# fallback for versions of lsblk <= 2.23 that don't have --paths, see _run_lsblk() above
uuid = 'N/A'
udevadm_path = self.module.get_bin_path('udevadm')
if not udevadm_path:
return uuid
cmd = [udevadm_path, 'info', '--query', 'property', '--name', device]
rc, out, err = self.module.run_command(cmd)
if rc != 0:
return uuid
# a snippet of the output of the udevadm command below will be:
# ...
# ID_FS_TYPE=ext4
# ID_FS_USAGE=filesystem
# ID_FS_UUID=57b1a3e7-9019-4747-9809-7ec52bba9179
# ...
m = re.search('ID_FS_UUID=(.*)\n', out)
if m:
uuid = m.group(1)
return uuid
def _run_findmnt(self, findmnt_path):
args = ['--list', '--noheadings', '--notruncate']
cmd = [findmnt_path] + args
@ -442,11 +467,16 @@ class LinuxHardware(Hardware):
if not self.MTAB_BIND_MOUNT_RE.match(options):
options += ",bind"
# _udevadm_uuid is a fallback for versions of lsblk <= 2.23 that don't have --paths
# see _run_lsblk() above
# https://github.com/ansible/ansible/issues/36077
uuid = uuids.get(device, self._udevadm_uuid(device))
mount_info = {'mount': mount,
'device': device,
'fstype': fstype,
'options': options,
'uuid': uuids.get(device, 'N/A')}
'uuid': uuid}
mount_info.update(mount_statvfs_info)