diff --git a/changelogs/fragments/68211-systemd-list-unit-files-parsing.yml b/changelogs/fragments/68211-systemd-list-unit-files-parsing.yml new file mode 100644 index 00000000000..421a28d8c37 --- /dev/null +++ b/changelogs/fragments/68211-systemd-list-unit-files-parsing.yml @@ -0,0 +1,2 @@ +bugfixes: + - service_facts - Now correctly parses systemd list-unit-files for systemd >=245 diff --git a/lib/ansible/modules/system/service_facts.py b/lib/ansible/modules/system/service_facts.py index f405abf9462..5f8b4d52d90 100644 --- a/lib/ansible/modules/system/service_facts.py +++ b/lib/ansible/modules/system/service_facts.py @@ -212,9 +212,10 @@ class SystemctlScanService(BaseService): services[service_name] = {"name": service_name, "state": state_val, "status": "unknown", "source": "systemd"} rc, stdout, stderr = self.module.run_command("%s list-unit-files --no-pager --type service --all" % systemctl_path, use_unsafe_shell=True) for line in [svc_line for svc_line in stdout.split('\n') if '.service' in svc_line and 'not-found' not in svc_line]: + # there is one more column (VENDOR PRESET) from `systemctl list-unit-files` for systemd >= 245 try: - service_name, status_val = line.split() - except ValueError: + service_name, status_val = line.split()[:2] + except IndexError: self.module.fail_json(msg="Malformed output discovered from systemd list-unit-files: {0}".format(line)) if service_name not in services: services[service_name] = {"name": service_name, "state": "unknown", "status": status_val, "source": "systemd"}