mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
fixed for chrrot as ignore error still has rc=0
This commit is contained in:
parent
350a32bd95
commit
2cb658925b
1 changed files with 8 additions and 9 deletions
|
@ -298,7 +298,14 @@ def main():
|
||||||
# check service data, cannot error out on rc as it changes across versions, assume not found
|
# check service data, cannot error out on rc as it changes across versions, assume not found
|
||||||
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
|
(rc, out, err) = module.run_command("%s show '%s'" % (systemctl, unit))
|
||||||
|
|
||||||
|
if out.find('ignoring request') != -1:
|
||||||
|
# fallback list-unit-files as show does not work on some systems (chroot)
|
||||||
|
# not used as primary as it skips some services (like those using init.d) and requires .service/etc notation
|
||||||
|
(rc, out, err) = module.run_command("%s list-unit-files '%s'" % (systemctl, unit))
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
|
is_systemd = True
|
||||||
|
|
||||||
|
elif rc == 0:
|
||||||
# load return of systemctl show into dictionary for easy access and return
|
# load return of systemctl show into dictionary for easy access and return
|
||||||
multival = []
|
multival = []
|
||||||
if out:
|
if out:
|
||||||
|
@ -328,14 +335,6 @@ def main():
|
||||||
if is_systemd and 'LoadError' in result['status']:
|
if is_systemd and 'LoadError' in result['status']:
|
||||||
module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
|
module.fail_json(msg="Error loading unit file '%s': %s" % (unit, result['status']['LoadError']))
|
||||||
|
|
||||||
elif out.find('ignoring request') != -1:
|
|
||||||
# fallback list-unit-files as show does not work on some systems (chroot)
|
|
||||||
# not used as primary as it skips some services (like those using init.d) and requires .service/etc notation
|
|
||||||
(rc, out, err) = module.run_command("%s list-unit-files '%s'" % (systemctl, unit))
|
|
||||||
if rc == 0:
|
|
||||||
is_systemd = True
|
|
||||||
|
|
||||||
|
|
||||||
# Does service exist?
|
# Does service exist?
|
||||||
found = is_systemd or is_initd
|
found = is_systemd or is_initd
|
||||||
if is_initd and not is_systemd:
|
if is_initd and not is_systemd:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue