mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-15 20:37:43 +00:00
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
This commit is contained in:
parent
112050ee7a
commit
33ae6c1018
2 changed files with 9 additions and 0 deletions
4
changelogs/fragments/12235-filesystem-busybox-blkid.yml
Normal file
4
changelogs/fragments/12235-filesystem-busybox-blkid.yml
Normal file
|
|
@ -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)."
|
||||
|
|
@ -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)])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue