mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-06-18 22:03:04 +00:00
[PR #12235/33ae6c10 backport][stable-13] filesystem: handle BusyBox blkid output when detecting existing filesystem (#12273)
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
(cherry picked from commit 33ae6c1018)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
ee4d63acbd
commit
265b9bf546
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