systemd - account for templated unit files when searching for service (#72702)

Related to issue #71528 and PR #72337

Co-authored-by: Martin Polden <mpolden@mpolden.no>
This commit is contained in:
Sam Doran 2020-12-02 21:51:45 -05:00 committed by GitHub
parent d05b26115b
commit a788ea0132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -0,0 +1,4 @@
bugfixes:
- >
systemd - account for templated unit files using ``@`` when searching for
the unit file (https://github.com/ansible/ansible/pull/72347#issuecomment-730626228)

View file

@ -415,7 +415,9 @@ def main():
elif err and rc == 1 and 'Failed to parse bus message' in err:
result['status'] = parse_systemctl_show(to_native(out).split('\n'))
(rc, out, err) = module.run_command("{systemctl} list-unit-files '{unit}*'".format(systemctl=systemctl, unit=unit))
unit, sep, suffix = unit.partition('@')
unit_search = '{unit}{sep}*'.format(unit=unit, sep=sep)
(rc, out, err) = module.run_command("{systemctl} list-unit-files '{unit_search}'".format(systemctl=systemctl, unit_search=unit_search))
is_systemd = unit in out
(rc, out, err) = module.run_command("{systemctl} is-active '{unit}'".format(systemctl=systemctl, unit=unit))