Get serial number of NVMe device without sg_inq (#70284)
* Get serial number of NVMe device without sg_inq * Add changlelog for #70284 * Use get_file_content() to get serial number from a file
This commit is contained in:
parent
8b96caf712
commit
953aa26286
2 changed files with 9 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- Facts collection - get serial number of NVMe device without sg_inq (https://github.com/ansible/ansible/issues/66663).
|
|
@ -700,6 +700,9 @@ class LinuxHardware(Hardware):
|
|||
|
||||
sg_inq = self.module.get_bin_path('sg_inq')
|
||||
|
||||
# we can get NVMe device's serial number from /sys/block/<name>/device/serial
|
||||
serial_path = "/sys/block/%s/device/serial" % (block)
|
||||
|
||||
if sg_inq:
|
||||
device = "/dev/%s" % (block)
|
||||
rc, drivedata, err = self.module.run_command([sg_inq, device])
|
||||
|
@ -707,6 +710,10 @@ class LinuxHardware(Hardware):
|
|||
serial = re.search(r"Unit serial number:\s+(\w+)", drivedata)
|
||||
if serial:
|
||||
d['serial'] = serial.group(1)
|
||||
else:
|
||||
serial = get_file_content(serial_path)
|
||||
if serial:
|
||||
d['serial'] = serial
|
||||
|
||||
for key, test in [('removable', '/removable'),
|
||||
('support_discard', '/queue/discard_granularity'),
|
||||
|
|
Loading…
Reference in a new issue