Comments (12)
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the component bot command.
from ansible.
@belope ansible-core
2.15 is not supported and no longer receives bug fixes. Please test against one of the supported versions of ansible-core
, preferably the most recent one, to see whether the bug has been fixed.
from ansible.
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.
from ansible.
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 systemctl --failed
and systemctl list-units --failed
and systemctl status
show no failed services the ansible module stil returns this "loaded" systemd service as failed, even though when directly asking on the ubuntu system there is no "loaded" service:
systemctl status loaded
Unit loaded.service could not be found
from ansible.
We do both:
systemctl list-units --type service --all"
and
systemctl list-unit-files --type service --all
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.
from ansible.
ok, on the affected system I can see the following:
systemctl list-units --type service --all|grep failed
grub-initrd-fallback.service loaded inactive dead GRUB failed boot detection
I believe that is why I see the "loaded" service, because ansible is taking the failed not from the state, but from description.
Could you please check if my assumption is correct?
from ansible.
no, we take that from the different state fields (systemd has many), iirc its ActiveState
from ansible.
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 another ubuntu server I can see 2 failed services in ansible facts, loaded and motd-news.service, but only motd-news in the systemctl --failed output as well as in the list units output
systemctl list-units --type service --all|grep failed
grub-initrd-fallback.service loaded inactive dead GRUB failed boot detection
● motd-news.service loaded failed failed Message of the Day
On the server with only loaded as failed I don't see any service where either ACTIVE or SUB are failed.
from ansible.
I have narrowed the problem with the help of my colleague to this portion of the code, lines 275-279:
for bad in self.BAD_STATES: if bad in fields: # dot is 0 status_val = bad fields = fields[1:] break
using the BAD_STATES = frozenset(['not-found', 'masked', 'failed'])
on ubuntu the incorrectly parsed service is as follows:
grub-initrd-fallback.service loaded inactive dead GRUB failed boot detection
the not-found, masked or failed services should norrmally have a ● sign on the beggining of the line, thus the removal of the first fields fiield (fields = fields[1:]) is necessary. However, in our situation, the "bad" state is matched in the service description, thus moving the index creates an incorrect failed service with the name "loaded".
the solution should probably be to not include description in the check for bad fields i guess? Or to use systemctl list-units --type service --all --plain to eliminate the ● sign altogether?
Could you look into this?
from ansible.
I'll try using plain, it seems like a better solution
diff --git a/lib/ansible/modules/service_facts.py b/lib/ansible/modules/service_facts.py
index c15533b1bb..916e3ec9e5 100644
--- a/lib/ansible/modules/service_facts.py
+++ b/lib/ansible/modules/service_facts.py
@@ -263,7 +263,7 @@ class SystemctlScanService(BaseService):
def _list_from_units(self, systemctl_path, services):
# list units as systemd sees them
- rc, stdout, stderr = self.module.run_command("%s list-units --no-pager --type service --all" % systemctl_path, use_unsafe_shell=True)
+ rc, stdout, stderr = self.module.run_command("%s list-units --no-pager --type service --all --plain" % systemctl_path, use_unsafe_shell=True)
if rc != 0:
self.module.warn("Could not list units from systemd: %s" % stderr)
else:
@@ -275,7 +275,6 @@ class SystemctlScanService(BaseService):
for bad in self.BAD_STATES:
if bad in fields: # dot is 0
status_val = bad
- fields = fields[1:]
break
else:
# active/inactive
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.
from ansible.
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)
As the --plain option has already removed the need to move the fileds index, I would propose to remove the whole for bad in fields for cyclus, as the status value should now be in the correct status_val = fields[2], however as you left the for cyclus in the code it currently detects those bad values in any field and sets status_val regardless of the fields[2] value as it doesn't enter the else branch.
from ansible.
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'
from ansible.
Related Issues (20)
- rpm_key module does nothing if it finds a partial match of already installed keys HOT 4
- Python 3.7 Support Removed To Early? HOT 6
- Avoid doing ssh connection if _remote_expand_user already failed HOT 2
- ansible.builtin.dnf doesn't install i686 packages HOT 1
- [ansible.builtin.copy] Fails on filesystems which do not support chmod HOT 7
- if ansible.builtin.fileglob plugin is used in ansible.builtin.template, it searches under files/ HOT 1
- Warnings about discovered Python interpreter on any play in version 2.17.0 HOT 3
- Regression with ansible_pkg_mgr discovery on Amazon Linux 2 HOT 7
- `file`: incomplete diff when creating parent directories HOT 1
- `file`: incomplete/misleading/missing diff when recursively setting attributes HOT 1
- systemd module silently fails to enable generated serviced unit HOT 9
- Add ability to break out of loop on a task HOT 2
- This breaks the ability to update RHEL-7 machines HOT 2
- `meta: end_host` returns `rc=2` when run in a rescue block HOT 1
- ansible.builtin.tempfile state:absent error HOT 5
- File descriptor leak in lib/ansible/plugins/connection/ssh.py HOT 3
- ansible.builtin.get_url doesn't support redirects HOT 3
- `unarchive`: Using the `include` option fails with `.tar.xz` archive HOT 3
- service_facts module on OpenBSD does not support '=' within service variables (too many values to unpack (expected 2)) HOT 2
- remote_user used with a loop results in fatal "item is undefined" HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible.