From 3942d29448d16b4ef8e9682b4d08fd03d1dbe2cd Mon Sep 17 00:00:00 2001 From: Dawud Date: Mon, 29 Jan 2024 17:32:31 +0000 Subject: [PATCH] Fix wipe-disks role to work on util-linux >= 2.37 On newer versions of util-linux, the ``wipe_disks`` role was not properly configured due to the fact that ``lsblk -J`` returns a slightly different output than what was previously returned. Previously the output would contain a key called ``mountpoint``, however this has been changed to ``mountpoints``. This has now been fixed by looking at the new key as well as the old key. Closes-bug: #2051859 Change-Id: I2a59f4eb3ae27f37fda38e05924315887cb04c41 --- ansible/roles/wipe-disks/library/blockdevice_info.py | 12 +++++++++--- releasenotes/notes/wipe-disks-0e72c9c8b7bf7e18.yaml | 7 +++++++ 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/wipe-disks-0e72c9c8b7bf7e18.yaml diff --git a/ansible/roles/wipe-disks/library/blockdevice_info.py b/ansible/roles/wipe-disks/library/blockdevice_info.py index b5fa5840c..4633e69b7 100644 --- a/ansible/roles/wipe-disks/library/blockdevice_info.py +++ b/ansible/roles/wipe-disks/library/blockdevice_info.py @@ -28,8 +28,14 @@ import json from ansible.module_utils.basic import AnsibleModule def _has_mounts(device): - if device["mountpoint"]: - return True + try: + if device["mountpoint"]: + return True + # If unmounted, the JSON output contains "mountpoints": [null] so we handle + # the KeyError here. + except KeyError: + if device["mountpoints"][0]: + return True for child in device.get("children", []): if _has_mounts(child): return True @@ -69,4 +75,4 @@ def main(): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/releasenotes/notes/wipe-disks-0e72c9c8b7bf7e18.yaml b/releasenotes/notes/wipe-disks-0e72c9c8b7bf7e18.yaml new file mode 100644 index 000000000..4039359cf --- /dev/null +++ b/releasenotes/notes/wipe-disks-0e72c9c8b7bf7e18.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixes the ``wipe-disks`` role which was failing on supported host operating + systems due to a change in the output format of ``lsblk -J`` in + ``util-linux`` version ``2.37``. LP#2051859 + __