Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup: properly detect is_chroot on Btrfs #55089

Merged
merged 3 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/55006-setup-is_chroot-btrfs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- setup - properly detect is_chroot on Btrfs (https://github.com/ansible/ansible/issues/55006)
16 changes: 13 additions & 3 deletions lib/ansible/module_utils/facts/system/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ansible.module_utils.facts.collector import BaseFactCollector


def is_chroot():
def is_chroot(module=None):

is_chroot = None

Expand All @@ -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')
bcoca marked this conversation as resolved.
Show resolved Hide resolved
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

Expand All @@ -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)}
2 changes: 1 addition & 1 deletion lib/ansible/modules/system/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down