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 37960ccc87
)
This commit is contained in:
parent
278aa94f1f
commit
8f2e6abbcf
2 changed files with 6 additions and 0 deletions
2
changelogs/fragments/systemd-warn-on-chroot.yaml
Normal file
2
changelogs/fragments/systemd-warn-on-chroot.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- systemd - warn when exeuting in a chroot environment rather than failing (https://github.com/ansible/ansible/pull/43904)
|
|
@ -251,6 +251,7 @@ status:
|
|||
import os
|
||||
|
||||
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
|
||||
|
||||
|
@ -486,6 +487,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…
Reference in a new issue