summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Olsen <jakeo@users.noreply.github.com>2019-01-14 15:45:05 -0500
committerToshio Kuratomi <a.badger@gmail.com>2019-01-21 08:34:11 -0800
commitc77f6b1d8c567cbc2d1a6b041c1ee588937baeab (patch)
treebeb23a8e10fec99bed2ad888699c60d92366f23e
parent182b5c621c1fff94d12f39db3a633947083602fa (diff)
downloadansible-c77f6b1d8c567cbc2d1a6b041c1ee588937baeab.tar.gz
check for chroot in systemd module (#43904)
* check for result['status'] in systemd module * instead of checking for result['state'], actually check for chroot and warn * allow systemctl status to work if in a chroot, update warn text * simply change warning message (cherry picked from commit 37960ccc87fb3711893d986e6d512920e095044f)
-rw-r--r--changelogs/fragments/systemd-warn-on-chroot.yaml2
-rw-r--r--lib/ansible/modules/system/systemd.py4
2 files changed, 6 insertions, 0 deletions
diff --git a/changelogs/fragments/systemd-warn-on-chroot.yaml b/changelogs/fragments/systemd-warn-on-chroot.yaml
new file mode 100644
index 0000000000..148db8a5f0
--- /dev/null
+++ b/changelogs/fragments/systemd-warn-on-chroot.yaml
@@ -0,0 +1,2 @@
+bugfixes:
+ - systemd - warn when exeuting in a chroot environment rather than failing (https://github.com/ansible/ansible/pull/43904)
diff --git a/lib/ansible/modules/system/systemd.py b/lib/ansible/modules/system/systemd.py
index 9ea6868d55..5b591e0f3a 100644
--- a/lib/ansible/modules/system/systemd.py
+++ b/lib/ansible/modules/system/systemd.py
@@ -238,6 +238,7 @@ status:
''' # NOQA
from ansible.module_utils.basic import AnsibleModule
+from ansible.module_utils.facts.system.chroot import is_chroot
from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
from ansible.module_utils._text import to_native
@@ -450,6 +451,9 @@ def main():
(rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
if rc != 0:
module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err))
+ # check for chroot
+ elif is_chroot():
+ 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?
module.fail_json(msg="Service is in unknown state", status=result['status'])