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
pull/50795/head
Jacob Olsen 6 years ago committed by Sam Doran
parent 3b5ac77a16
commit 37960ccc87

@ -0,0 +1,2 @@
bugfixes:
- systemd - warn when exeuting in a chroot environment rather than failing (https://github.com/ansible/ansible/pull/43904)

@ -254,6 +254,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
@ -493,6 +494,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'])

Loading…
Cancel
Save