mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
setup: properly detect is_chroot on Btrfs (#55089)
* setup: properly detect is_chroot on Btrfs Fixes #55006 * Use get_bin_path for stat * Remove comment
This commit is contained in:
parent
cd00934375
commit
a40c1ed811
3 changed files with 16 additions and 4 deletions
|
@ -8,7 +8,7 @@ import os
|
|||
from ansible.module_utils.facts.collector import BaseFactCollector
|
||||
|
||||
|
||||
def is_chroot():
|
||||
def is_chroot(module=None):
|
||||
|
||||
is_chroot = None
|
||||
|
||||
|
@ -22,7 +22,17 @@ def is_chroot():
|
|||
is_chroot = my_root.st_ino != proc_root.st_ino or my_root.st_dev != proc_root.st_dev
|
||||
except Exception:
|
||||
# I'm not root or no proc, fallback to checking it is inode #2
|
||||
is_chroot = (my_root.st_ino != 2)
|
||||
fs_root_ino = 2
|
||||
|
||||
if module is not None:
|
||||
stat_path = module.get_bin_path('stat')
|
||||
if stat_path:
|
||||
cmd = [stat_path, '-f', '--format=%T', '/']
|
||||
rc, out, err = module.run_command(cmd)
|
||||
if 'btrfs' in out:
|
||||
fs_root_ino = 256
|
||||
|
||||
is_chroot = (my_root.st_ino != fs_root_ino)
|
||||
|
||||
return is_chroot
|
||||
|
||||
|
@ -32,4 +42,4 @@ class ChrootFactCollector(BaseFactCollector):
|
|||
_fact_ids = set(['is_chroot'])
|
||||
|
||||
def collect(self, module=None, collected_facts=None):
|
||||
return {'is_chroot': is_chroot()}
|
||||
return {'is_chroot': is_chroot(module)}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue