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)])