Skip to content

Commit f5cffaa

Browse files
authored
Workaround for missing NVMe serial in facts (#386)
The sap-hana-storage playbook was failing on SLES 12 SP5 instances because the 'serial' attribute for NVMe devices was missing from the facts gathered by Ansible. Implements a workaround to manually gather the NVMe device serial numbers by reading them directly from the `/sys` filesystem. Fix ansible-lint warnings related to task names.
1 parent 384d055 commit f5cffaa

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

ansible/playbooks/roles/qe_sap_storage/tasks/generic_tasks/prepare_storage.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,28 @@
3939

4040
# Using data exported by terraform in ebs_id_to_device_name, create a
4141
# sdX -> nvmeXn1 map, based on the device serial
42+
- name: Get serial number for each nvme device
43+
ansible.builtin.command: cat /sys/class/block/{{ item.key }}/device/serial
44+
register: nvme_serial_list
45+
loop: "{{ nvme_device_list }}"
46+
changed_when: false
47+
when:
48+
- cloud_platform_is_aws and not aws_machine_type_is_r4
49+
4250
- name: Build /dev/sdX to nvme device mapping for attached volumes
4351
ansible.builtin.set_fact:
44-
sd_to_nvme_map: "{{ sd_to_nvme_map | default({}) | combine({ device_name: '/dev/' ~ nvme_dev.key }) }}"
45-
loop: "{{ nvme_device_list }}"
46-
loop_control:
47-
loop_var: nvme_dev
52+
sd_to_nvme_map: "{{ sd_to_nvme_map | default({}) | combine({ device_name: '/dev/' ~ item.item.key }) }}"
53+
loop: "{{ nvme_serial_list.results }}"
4854
vars:
49-
# terraform (aws) exports the serial as "vol-xxx" while the system sees it as "volxxx", so we need to omit the '-'
50-
volume_id: "{{ nvme_dev.value.serial | regex_replace('^vol(?!-)', 'vol-') }}"
55+
# terraform (aws) exports the serial as "vol-xxx" while the system sees it as "volxxx", so we need to omit the '-'.
56+
# The regex is constructed to not match on serials that already start with vol-
57+
volume_id: "{{ item.stdout | regex_replace('^vol(?!-)', 'vol-') }}"
5158
device_name: "{{ ebs_id_to_device_name_map.get(volume_id, '') }}"
5259
when:
5360
- cloud_platform_is_aws and not aws_machine_type_is_r4
5461
- device_name != '' # only map if the serial id exists in the exported serial ids from terraform
5562

56-
- name: "Adjust PV list for storage profile {{ item.key }}"
63+
- name: Adjust PV list for storage profile {{ item.key }}
5764
ansible.builtin.set_fact:
5865
adjusted_pv: >-
5966
{{
@@ -69,7 +76,7 @@
6976
msg: "Using PV list: {{ (adjusted_pv is defined and (adjusted_pv | length) > 0) | ternary(adjusted_pv, item.value.pv) }}"
7077

7178
# Create Volume Group
72-
- name: "SAP Storage Preparation - Volume Group One: {{ [qe_sap_storage_cloud_type | upper, item.value.name] | join(' - ') }}"
79+
- name: "SAP Storage Preparation - Volume Group One: {{ item.value.name + ' on ' + sap_storage_cloud_type }}"
7380
community.general.lvg:
7481
vg: "{{ item.value.vg }}"
7582
pvs: "{{ (adjusted_pv is defined and (adjusted_pv | length) > 0) | ternary(adjusted_pv, item.value.pv) }}"
@@ -85,7 +92,7 @@
8592
when: adjusted_pv is defined
8693

8794
# Create Logical Group - One
88-
- name: "SAP Storage Preparation - Logical Volume - One: {{ [qe_sap_storage_cloud_type | upper, item.value.name] | join(' - ') }}"
95+
- name: "SAP Storage Preparation - Logical Volume One: {{ item.value.name + ' on ' + sap_storage_cloud_type }}"
8996
community.general.lvol:
9097
vg: "{{ item.value.vg }}"
9198
lv: "{{ item.value.lv }}"
@@ -94,7 +101,7 @@
94101
- "item.value.numluns == '1'"
95102

96103
# Create Logical Group - Striped
97-
- name: "SAP Storage Preparation - Logical Volume - Striped: {{ [qe_sap_storage_cloud_type | upper, item.value.name] | join(' - ') }}"
104+
- name: "SAP Storage Preparation - Logical Volume Striped: {{ item.value.name + ' on ' + sap_storage_cloud_type }}"
98105
community.general.lvol:
99106
vg: "{{ item.value.vg }}"
100107
lv: "{{ item.value.lv }}"
@@ -104,13 +111,13 @@
104111
- "item.value.numluns != '1'"
105112

106113
# Create Filesystem
107-
- name: "SAP Storage Preparation - Filesystem: {{ [qe_sap_storage_cloud_type | upper, item.value.name] | join(' - ') }}"
114+
- name: "SAP Storage Preparation - Filesystem: {{ item.value.name + ' on ' + sap_storage_cloud_type }}"
108115
community.general.filesystem:
109116
fstype: xfs
110117
dev: "/dev/{{ item.value.vg }}/{{ item.value.lv }}"
111118

112119
# Mount Filesystem
113-
- name: "SAP Storage Preparation - Mount: {{ [qe_sap_storage_cloud_type | upper, item.value.name] | join(' - ') }}"
120+
- name: "SAP Storage Preparation - Mount: {{ item.value.name + ' on ' + sap_storage_cloud_type }}"
114121
ansible.posix.mount:
115122
path: "{{ item.value.directory }}"
116123
fstype: xfs

0 commit comments

Comments
 (0)