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
This commit is contained in:
Jacob Olsen 2019-01-14 15:45:05 -05:00 committed by Sam Doran
parent 3b5ac77a16
commit 37960ccc87
2 changed files with 6 additions and 0 deletions

View file

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

View file

@ -254,6 +254,7 @@ status:
''' # NOQA ''' # NOQA
from ansible.module_utils.basic import AnsibleModule 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.service import sysv_exists, sysv_is_enabled, fail_if_missing
from ansible.module_utils._text import to_native 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)) (rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
if rc != 0: if rc != 0:
module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err)) 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: else:
# this should not happen? # this should not happen?
module.fail_json(msg="Service is in unknown state", status=result['status']) module.fail_json(msg="Service is in unknown state", status=result['status'])