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
pull/70866/head
Mykola Grygoriev 4 years ago committed by GitHub
parent 8b96caf712
commit 953aa26286
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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') 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: if sg_inq:
device = "/dev/%s" % (block) device = "/dev/%s" % (block)
rc, drivedata, err = self.module.run_command([sg_inq, device]) 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) serial = re.search(r"Unit serial number:\s+(\w+)", drivedata)
if serial: if serial:
d['serial'] = serial.group(1) d['serial'] = serial.group(1)
else:
serial = get_file_content(serial_path)
if serial:
d['serial'] = serial
for key, test in [('removable', '/removable'), for key, test in [('removable', '/removable'),
('support_discard', '/queue/discard_granularity'), ('support_discard', '/queue/discard_granularity'),

Loading…
Cancel
Save