From 33ae6c10181205e8ccf47e65367a95b013031f1b Mon Sep 17 00:00:00 2001 From: Alexei Znamensky <103110+russoz@users.noreply.github.com> Date: Mon, 15 Jun 2026 06:31:50 +1200 Subject: [PATCH] filesystem: handle BusyBox `blkid` output when detecting existing filesystem (#12235) * fix(filesystem): handle BusyBox blkid output when detecting existing filesystem BusyBox blkid ignores util-linux -o/-s flags and outputs the full device info line instead of just the filesystem type. Parse the TYPE= field from the raw output when it does not look like a plain type name. Fixes #7283 * changelog: add fragment for PR 12235 --- changelogs/fragments/12235-filesystem-busybox-blkid.yml | 4 ++++ plugins/modules/filesystem.py | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 changelogs/fragments/12235-filesystem-busybox-blkid.yml diff --git a/changelogs/fragments/12235-filesystem-busybox-blkid.yml b/changelogs/fragments/12235-filesystem-busybox-blkid.yml new file mode 100644 index 0000000000..7116b85e90 --- /dev/null +++ b/changelogs/fragments/12235-filesystem-busybox-blkid.yml @@ -0,0 +1,4 @@ +bugfixes: + - "filesystem - handle BusyBox ``blkid`` output to correctly detect existing filesystems on systems like Alpine Linux + (https://github.com/ansible-collections/community.general/issues/7283, + https://github.com/ansible-collections/community.general/pull/12235)." diff --git a/plugins/modules/filesystem.py b/plugins/modules/filesystem.py index 746f1660d0..35585ae494 100644 --- a/plugins/modules/filesystem.py +++ b/plugins/modules/filesystem.py @@ -683,6 +683,11 @@ def main(): cmd = module.get_bin_path("blkid", required=True) rc, raw_fs, err = module.run_command([cmd, "-c", os.devnull, "-o", "value", "-s", "TYPE", str(dev)]) fs = raw_fs.strip() + # BusyBox blkid may ignore -o/-s flags and output the full device info line, + # e.g. '/dev/sda2: UUID="..." TYPE="btrfs"' instead of just 'btrfs' + if fs and " " in fs: + type_match = re.search(r'\bTYPE="?([^"\s]+)"?', raw_fs) + fs = type_match.group(1) if type_match else "" if not fs and platform.system() == "FreeBSD": cmd = module.get_bin_path("fstyp", required=True) rc, raw_fs, err = module.run_command([cmd, str(dev)])