Browse code

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)

Jacob Olsen authored on 2019/01/15 05:45:05
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,2 @@
0
+bugfixes:
1
+  - systemd - warn when exeuting in a chroot environment rather than failing (https://github.com/ansible/ansible/pull/43904)
... ...
@@ -238,6 +238,7 @@ status:
238 238
 '''  # NOQA
239 239
 
240 240
 from ansible.module_utils.basic import AnsibleModule
241
+from ansible.module_utils.facts.system.chroot import is_chroot
241 242
 from ansible.module_utils.service import sysv_exists, sysv_is_enabled, fail_if_missing
242 243
 from ansible.module_utils._text import to_native
243 244
 
... ...
@@ -450,6 +451,9 @@ def main():
450 450
                         (rc, out, err) = module.run_command("%s %s '%s'" % (systemctl, action, unit))
451 451
                         if rc != 0:
452 452
                             module.fail_json(msg="Unable to %s service %s: %s" % (action, unit, err))
453
+            # check for chroot
454
+            elif is_chroot():
455
+                module.warn("Target is a chroot. This can lead to false positives or prevent the init system tools from working.")
453 456
             else:
454 457
                 # this should not happen?
455 458
                 module.fail_json(msg="Service is in unknown state", status=result['status'])