systemd and service modules don't check is-enabled stdout values, causing false positives #28247
Labels
affects_2.10
This issue/PR affects Ansible v2.10
bot_closed
bug
This issue/PR relates to a bug.
has_pr
This issue has an associated PR.
module
This issue/PR relates to a module.
needs_info
This issue requires further information. Please answer any outstanding questions.
P3
Priority 3 - Approved, No Time Limitation
support:core
This issue/PR relates to code supported by the Ansible Engineering Team.
system
System category
verified
This issue has been verified/reproduced by maintainer
ISSUE TYPE
COMPONENT NAME
systemd
service
ANSIBLE VERSION
CONFIGURATION
None of significance
OS / ENVIRONMENT
N/A
SUMMARY
Both
https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/system/service.py#L536 and
https://github.com/ansible/ansible/blob/stable-2.3/lib/ansible/modules/system/systemd.py#L383
have the same basic logic check failure. Their purposes in each module are essentially the same for the sake of this bug, and both locations need to be fixed:
Neither module properly parses the return code '0' coupled with the stdout value 'indirect'. They return the false positive that a systemd service/Unit file is enabled when it is not, therefore always producing a Changed status and attempting to disable a service when disabling it does nothing.
From the systemctl man page, 0 and indirect indicates that the "Unit file itself is not enabled, but it has a non-empty Also= setting in the "[Install]" section, listing other unit files that might be enabled."
With any systemd service that has an Also= section, ansible will indicate that it has disabled a service that may already be disabled.
STEPS TO REPRODUCE
An RHEL 7 type series linux will show this error well:
EXPECTED RESULTS (My best guess)
"systemctl is-enabled" should interpret stdout strings when the return code is 0 as follows:
enabled* : Service is enabled.
static: Service is disabled, and if a user is attempting to enable the service, return an error.
indirect: Service is disabled.
I suggest that if a user desires to enable/disable/stop/start/query a parallel Unit file that will make a queried unit file return 'indirect', that they should do so explicitly.
ACTUAL RESULTS
A unit service which has a return code of 0 from 'systemctl is-enabled' is assumed to be enabled when it may not be, because stdout return values aren't checked at all.
The text was updated successfully, but these errors were encountered: