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
pull/55154/head
Martin Krizek 6 years ago committed by GitHub
parent cd00934375
commit a40c1ed811
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- setup - properly detect is_chroot on Btrfs (https://github.com/ansible/ansible/issues/55006)

@ -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)}

@ -508,7 +508,7 @@ def main():
if rc != 0:
module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err))
# check for chroot
elif is_chroot():
elif is_chroot(module):
module.warn("Target is a chroot. This can lead to false positives or prevent the init system tools from working.")
else:
# this should not happen?

Loading…
Cancel
Save