From a2eb227970b5f53a648af3daf58d745d2f33067e Mon Sep 17 00:00:00 2001 From: Adam Miller Date: Tue, 9 Apr 2019 23:17:30 -0500 Subject: [PATCH] facts: correctly detect xen paravirt vs hvm cpuinfo (#49320) * facts: correctly detect xen paravirt vs hvm cpuinfo Fixes #49039 Signed-off-by: Adam Miller * provide default val if we IndexError Signed-off-by: Adam Miller --- .../49039-facts-xen-paravirt-cpuinfo.yaml | 2 ++ .../module_utils/facts/hardware/linux.py | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 changelogs/fragments/49039-facts-xen-paravirt-cpuinfo.yaml diff --git a/changelogs/fragments/49039-facts-xen-paravirt-cpuinfo.yaml b/changelogs/fragments/49039-facts-xen-paravirt-cpuinfo.yaml new file mode 100644 index 0000000000..93e7a687a9 --- /dev/null +++ b/changelogs/fragments/49039-facts-xen-paravirt-cpuinfo.yaml @@ -0,0 +1,2 @@ +minor_changes: + - "ansible facts properly detect xen paravirt vs hvm" diff --git a/lib/ansible/module_utils/facts/hardware/linux.py b/lib/ansible/module_utils/facts/hardware/linux.py index 383e1670eb..5f37f8e370 100644 --- a/lib/ansible/module_utils/facts/hardware/linux.py +++ b/lib/ansible/module_utils/facts/hardware/linux.py @@ -187,13 +187,18 @@ class LinuxHardware(Hardware): data = line.split(":", 1) key = data[0].strip() + try: + val = data[1].strip() + except IndexError: + val = "" + if xen: if key == 'flags': # Check for vme cpu flag, Xen paravirt does not expose this. # Need to detect Xen paravirt because it exposes cpuinfo # differently than Xen HVM or KVM and causes reporting of # only a single cpu core. - if 'vme' not in data: + if 'vme' not in val: xen_paravirt = True # model name is for Intel arch, Processor (mind the uppercase P) @@ -202,7 +207,7 @@ class LinuxHardware(Hardware): if key in ['model name', 'Processor', 'vendor_id', 'cpu', 'Vendor', 'processor']: if 'processor' not in cpu_facts: cpu_facts['processor'] = [] - cpu_facts['processor'].append(data[1].strip()) + cpu_facts['processor'].append(val) if key == 'vendor_id': vendor_id_occurrence += 1 if key == 'model name': @@ -211,21 +216,21 @@ class LinuxHardware(Hardware): processor_occurence += 1 i += 1 elif key == 'physical id': - physid = data[1].strip() + physid = val if physid not in sockets: sockets[physid] = 1 elif key == 'core id': - coreid = data[1].strip() + coreid = val if coreid not in sockets: cores[coreid] = 1 elif key == 'cpu cores': - sockets[physid] = int(data[1].strip()) + sockets[physid] = int(val) elif key == 'siblings': - cores[coreid] = int(data[1].strip()) + cores[coreid] = int(val) elif key == '# processors': - cpu_facts['processor_cores'] = int(data[1].strip()) + cpu_facts['processor_cores'] = int(val) elif key == 'ncpus active': - i = int(data[1].strip()) + i = int(val) # Skip for platforms without vendor_id/model_name in cpuinfo (e.g ppc64le) if vendor_id_occurrence > 0: