-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ansible service_facts module returning failed loaded service on ubuntu 20.04 #83360
Comments
Files identified in the description: If these files are incorrect, please update the |
@belope |
This is intended, service_facts returns data on all services it can find and their state, for example this helps people looking for services in different state/status and enable combination. If you don't wan't failed services, this is easy to filter out from the results, but the data itself should reflect the state of the target. |
I apologise if I didn't explain my problem properly, I know that service facts returns failed services and I want that. On other operating systems (rhel based, debian) when you run systemctl --failed and there are no failed services both ansible and the direct command show the same thing. Only on ubuntu even though |
We do both:
and
To ensure we get a full list. There are many 'views' systemd returns, specially with the different ways it was implemented, this is the way we found to minimize discrepancies and get the most data. If you do other different queries, deviations are expected. |
ok, on the affected system I can see the following: |
no, we take that from the different state fields (systemd has many), iirc its ActiveState |
ok, any idea why I'm seeing the "loaded" systemd service? I would really like to figure this out as the only system that I can see this on is ubuntu and I would like to either not see it in the ansible output if it's there erroneously or figure out how to find what failed service to fix. On the server with only loaded as failed I don't see any service where either ACTIVE or SUB are failed. |
I have narrowed the problem with the help of my colleague to this portion of the code, lines 275-279: |
I'll try using plain, it seems like a better solution
let me know if that fixes it for you, the 'list from unit files' should overlap/overwrite this in any case and that pull from activestate, looking at the code now trying to figure out why that is not the case for you. |
I tried the proposed fix, it fixes one half of the problem. It correctly parses the fileds, however, it still wrongly detects any service that has one of the words 'not-found', 'masked', 'failed' in the description field (in my case the grub-initrd-fallback.service) |
That code handled that some versions of systemd were not consistent on showing a failed status even when the service had clearly failed as indicated by other fields. I'll need to check if all currently used versions now do so before removing that, though a better fix might just be to avoid the description as your own example shows grub as 'loaded' and 'inactive' and 'dead' |
Summary
When running
- name: populate service facts service_facts:
debugging ansible_facts.services variable shows on ubuntu hosts a service in failed state, specifically
'loaded': {'name': 'loaded', 'state': 'stopped', 'status': 'failed', 'source': 'systemd'}
running systemctl --failed on the host does not return any failed services
tested on more versions of ansible as behaving the same
Issue Type
Bug Report
Component Name
lib/ansible/modules/service_facts.py
Ansible Version
Configuration
OS / Environment
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=21.3
Steps to Reproduce
Expected Results
expected no services in failed state
Actual Results
Code of Conduct
The text was updated successfully, but these errors were encountered: