# Systemd test enabled workaround?

**URL:** <https://forum.ansible.com/t/systemd-test-enabled-workaround/40520>\
**Category:** Get Help\
**Created:** [February 22, 2025, 9:14am UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520 "2025-02-22T09:14:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CarlFK](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlfk/32/7668_2.png) [@CarlFK](https://forum.ansible.com/u/CarlFK)\
**Post date:** [February 22, 2025, 9:14am UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/1 "2025-02-22T09:14:07Z")

</div>

I just came across something I find strange:

```auto
- name: Enable the enabled-runtime service using shell command
  shell: systemctl enable --runtime baz

```

> <https://github.com/ansible/ansible/blob/devel/test/integration/targets/systemd/tasks/test_enabled_runtime.yml#L15C1-L15C40>

The next task:

```auto
- name: Enable enabled-runtime service
  systemd:
    name: baz.service
    enabled: true
  register: baz_test_1

```

is this the same workaround as in

> <https://github.com/ansible/ansible/issues/72451#issuecomment-771541032>
>
> \##### SUMMARY
> Ansible treats enabled-runtime equal to enabled, which causes pro…blems.
> 
> \##### ISSUE TYPE
> \- Bug Report
> 
> \##### COMPONENT NAME
> ansible.builtin.systemd\_service
> 
> systemd
> https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/systemd.py#L416
> https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/systemd.py#L470
> https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/systemd.py#L495
> 
> \##### ANSIBLE VERSION
> 
> \`\`\`paste below
> ansible 2.10.2
> config file = ./ansible.cfg
> configured module search path = \['./library'\]
> ansible python module location = ./venv/lib/python3.8/site-packages/ansible
> executable location = ./venv/bin/ansible
> python version = 3.8.6 (default, Sep 30 2020, 04:00:38) \[GCC 10.2.0\]
> \`\`\`
> 
> \##### CONFIGURATION
> 
> \`\`\`paste below
> ANSIBLE\_PIPELINING(./ansible.cfg) = True
> ANSIBLE\_SSH\_ARGS(./ansible.cfg) = -i ./.ssh.vpass -o ControlMaster=auto -o ControlPersist=30m -o ConnectionAttempts=100 -o UserKnownHostsFile=./known\_hosts
> \`\`\`
> 
> \##### OS / ENVIRONMENT
> 
> Linux pc 5.9.2-arch1-1 #1 SMP PREEMPT Thu, 29 Oct 2020 17:01:28 +0000 x86\_64 GNU/Linux
> 
> \##### STEPS TO REPRODUCE
> 1. A systemd service that is enabled only in runtime config (I don't know what causes this exactly, but that is how it is after initial boot...)
> 2. Than run an ansible playbook with this task:
> \`\`\`
> \- systemd:
> name: systemd-networkd
> enabled: yes
> \`\`\`
> 3. Run \`systemctl enable systemd-networkd\` and notice that it wasn't enabled before by ansible.
> 
> \##### EXPECTED RESULTS
> 
> I relied upon ansible truely enabling a service using aboves task e.g. it being equivalent to \`systemctl enable systemd-networkd\`, which it aparently isn't.
> Further down my playbook I reconfigured some other stuff and after a reboot the vm was without network, as ansible did not enable the service as it should have...
> 
> Also the documentation for the services and systemd module say:
> \> Whether the service should start on boot.
> 
> Which isn't satisfied in it's current state.
> 
> \##### ACTUAL RESULTS
> Ansible says it is in desired state and it wasn't modified, where as in fact the service won't launch at next boot at all...
> 
> 
> 
> 
> !component lib/ansible/modules/systemd\_service.py

---

<div class="post-metadata">

**Author:** ![CarlFK](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlfk/32/7668_2.png) [@CarlFK](https://forum.ansible.com/u/CarlFK)\
**Post date:** [February 22, 2025, 9:48am UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/2 "2025-02-22T09:48:34Z")

</div>

I copied some and tried to run them, seems one failed:

```auto
TASK [sysmd : assert] *********************************************************************************************
task path: /home/carl/src/bug_reports/absd/ansible/roles/sysmd/tasks/test_enabled_runtime.yml:42
fatal: [pi3]: FAILED! => {
    "assertion": "baz_test_1 is changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

PLAY RECAP ********************************************************************************************************
pi3 : ok=24 changed=6 unreachable=0 failed=1 skipped=0 rescued=0 ignored=2   

```

I fixed it:

```auto
 - name: Enable the enabled-runtime service using shell command
- shell: systemctl enable --runtime baz
+ shell: systemctl disable --runtime baz

```

I’m still not sure what is going on.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [February 22, 2025, 9:49am UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/3 "2025-02-22T09:49:46Z")

</div>

Doesn’t the service also need to be started?

```auto
- name: Enable and start enabled-runtime service
  ansible.builtin.systemd_service:
    name: baz.service
    enabled: true
    state: started

```

---

<div class="post-metadata">

**Author:** ![NomakCooper](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nomakcooper/32/7309_2.png) [@NomakCooper](https://forum.ansible.com/u/NomakCooper)\
**Post date:** [February 22, 2025, 3:27pm UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/4 "2025-02-22T15:27:49Z")

</div>

@CarlFK

I haven’t read all the messages on Element and I’m not quite sure what you’re trying to do, but from what I’ve seen in the **`systemd_service`** module’s code, the **`--runtime`** functions are not supported by the module.

You can set **`user`** mode and **`enable`** the service, but it will not use the **`--runtime`** function.

**`user`** mode is implemented by appending the appropriate flag to the **`systemctl`** command. In the code, you’ll see this right after retrieving systemctl’s binary

> <https://github.com/ansible/ansible/blob/2a3c93f593f4c0ea11e34b946aa45e5e6f463e76/lib/ansible/modules/systemd_service.py#L379-L380>

So if you set `scope: user`, the command becomes `systemctl --user …`, which runs the service in the current user’s context.

* * *

The service enabling operation takes place as follows:

It checks the value of the `enabled` parameter. If it’s **`true`** , it sets the action to **`enable`** , otherwise to **`disable`**.

> <https://github.com/ansible/ansible/blob/2a3c93f593f4c0ea11e34b946aa45e5e6f463e76/lib/ansible/modules/systemd_service.py#L504-L507>

It compares the **current** enabled state with the **desired** state. If they differ, it marks the result as changed and executes the corresponding **`enable`** or **`disable`** command:

> <https://github.com/ansible/ansible/blob/2a3c93f593f4c0ea11e34b946aa45e5e6f463e76/lib/ansible/modules/systemd_service.py#L538-L545>

* * *

For the **`runtime`** enablement, check the section that verifies if a service is enabled. After executing:

> <https://github.com/ansible/ansible/blob/2a3c93f593f4c0ea11e34b946aa45e5e6f463e76/lib/ansible/modules/systemd_service.py#L512-L513>

the code inspects the output:

> <https://github.com/ansible/ansible/blob/2a3c93f593f4c0ea11e34b946aa45e5e6f463e76/lib/ansible/modules/systemd_service.py#L516-L525>

if the output is **`enabled-runtime`** , the module does not consider the service as permanently **`enabled`** and will attempt to change it if **`enabled: true`** is requested. This means the module doesn’t support **`runtime`** enablement as a permanent configuration.

---

<div class="post-metadata">

**Author:** ![CarlFK](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlfk/32/7668_2.png) [@CarlFK](https://forum.ansible.com/u/CarlFK)\
**Post date:** [February 23, 2025, 6:04am UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/5 "2025-02-23T06:04:05Z")

</div>

This thread is just about the tests that are part of the Ansible repo. I can’t get the tests to pass.

Likely because I am not doing something right.

or because the tests are broken. which I doubt, but that is in line with:

> the **`--runtime`** functions are not supported by the module.

`- name: Enable enabled-runtime service`  
is from

> <https://github.com/ansible/ansible/blob/devel/test/integration/targets/systemd/tasks/test_enabled_runtime.yml#L17>

Once I get a good understanding of what and how Ansible works with systemd, then I can slowly try to implement what I need done. But that is out of scope for this thread. this thread is just about the running the tests that come with Ansible.

I pulled that whole role into my test repo, (symlink)

> <https://github.com/CarlFK/absd/blob/main/ansible/roles/systemd>

fiddled with my site.yml, the test seems to run, but fails:

```auto
TASK [systemd : Disable enabled-runtime service again] ************************************************************
task path: /home/carl/src/bug_reports/ansible/test/integration/targets/systemd/tasks/test_enabled_runtime.yml:36
<pi> ESTABLISH SSH CONNECTION FOR USER: root
<pi> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=10322 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/carl/.ansible/cp/232c16e386"' pi '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<pi> (0, b'/root\n', b"OpenSSH_8.9p1 Ubuntu-3ubuntu0.11, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/carl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/carl/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/carl/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2301978\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
<pi> ESTABLISH SSH CONNECTION FOR USER: root
<pi> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=10322 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/carl/.ansible/cp/232c16e386"' pi '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900 `" && echo ansible-tmp-1740270764.0062406-2302436-38070915003900="` echo /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900 `" ) && sleep 0'"'"''
<pi> (0, b'ansible-tmp-1740270764.0062406-2302436-38070915003900=/root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900\n', b"OpenSSH_8.9p1 Ubuntu-3ubuntu0.11, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/carl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/carl/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/carl/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2301978\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
Using module file /usr/lib/python3/dist-packages/ansible/modules/systemd.py
<pi> PUT /home/carl/.ansible/tmp/ansible-local-2301943uui0sygw/tmpvmudzntb TO /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py
<pi> SSH: EXEC sftp -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=10322 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/carl/.ansible/cp/232c16e386"' '[pi]'
<pi> (0, b'sftp> put /home/carl/.ansible/tmp/ansible-local-2301943uui0sygw/tmpvmudzntb /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py\n', b'OpenSSH_8.9p1 Ubuntu-3ubuntu0.11, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/carl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile \'~/.ssh/known_hosts\' -> \'/home/carl/.ssh/known_hosts\'\r\ndebug3: expanded UserKnownHostsFile \'~/.ssh/known_hosts2\' -> \'/home/carl/.ssh/known_hosts2\'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2301978\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "posix-rename@openssh.com" revision 1\r\ndebug2: Server supports extension "statvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "fstatvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "hardlink@openssh.com" revision 1\r\ndebug2: Server supports extension "fsync@openssh.com" revision 1\r\ndebug2: Server supports extension "lsetstat@openssh.com" revision 1\r\ndebug2: Server supports extension "limits@openssh.com" revision 1\r\ndebug2: Server supports extension "expand-path@openssh.com" revision 1\r\ndebug2: Unrecognised server extension "copy-data"\r\ndebug2: Unrecognised server extension "home-directory"\r\ndebug2: Unrecognised server extension "users-groups-by-id@openssh.com"\r\ndebug3: Sent message limits@openssh.com I:1\r\ndebug3: Received limits reply T:201 I:1\r\ndebug1: Using server download size 261120\r\ndebug1: Using server upload size 261120\r\ndebug1: Server handle limit 1019; using 64\r\ndebug2: Sending SSH2_FXP_REALPATH "."\r\ndebug3: Sent message fd 3 T:16 I:2\r\ndebug3: SSH2_FXP_REALPATH . -> /root\r\ndebug3: Looking up /home/carl/.ansible/tmp/ansible-local-2301943uui0sygw/tmpvmudzntb\r\ndebug2: Sending SSH2_FXP_STAT "/root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py"\r\ndebug3: Sent message fd 3 T:17 I:3\r\ndebug1: stat remote: No such file or directory\r\ndebug2: do_upload: upload local "/home/carl/.ansible/tmp/ansible-local-2301943uui0sygw/tmpvmudzntb" to remote "/root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py"\r\ndebug2: Sending SSH2_FXP_OPEN "/root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py"\r\ndebug3: Sent dest message SSH2_FXP_OPEN I:4 P:/root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py M:0x001a\r\ndebug3: Sent message SSH2_FXP_WRITE I:6 O:0 S:261120\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 6 261120 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:7 O:261120 S:31485\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 7 31485 bytes at 261120\r\ndebug3: Sent message SSH2_FXP_CLOSE I:5\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<pi> ESTABLISH SSH CONNECTION FOR USER: root
<pi> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=10322 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/carl/.ansible/cp/232c16e386"' pi '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/ /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py && sleep 0'"'"''
<pi> (0, b'', b"OpenSSH_8.9p1 Ubuntu-3ubuntu0.11, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/carl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/carl/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/carl/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2301978\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
<pi> ESTABLISH SSH CONNECTION FOR USER: root
<pi> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=10322 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/carl/.ansible/cp/232c16e386"' -tt pi '/bin/sh -c '"'"'/usr/bin/python3.11 /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/AnsiballZ_systemd.py && sleep 0'"'"''
<pi> (0, b'\r\n{"name": "baz.service", "changed": true, "status": {"Type": "simple", "ExitType": "main", "Restart": "no", "NotifyAccess": "none", "RestartUSec": "100ms", "TimeoutStartUSec": "1min 30s", "TimeoutStopUSec": "1min 30s", "TimeoutAbortUSec": "1min 30s", "TimeoutStartFailureMode": "terminate", "TimeoutStopFailureMode": "terminate", "RuntimeMaxUSec": "infinity", "RuntimeRandomizedExtraUSec": "0", "WatchdogUSec": "infinity", "WatchdogTimestampMonotonic": "0", "RootDirectoryStartOnly": "no", "RemainAfterExit": "no", "GuessMainPID": "yes", "MainPID": "0", "ControlPID": "0", "FileDescriptorStoreMax": "0", "NFileDescriptorStore": "0", "StatusErrno": "0", "Result": "success", "ReloadResult": "success", "CleanResult": "success", "UID": "[not set]", "GID": "[not set]", "NRestarts": "0", "OOMPolicy": "stop", "ExecMainStartTimestampMonotonic": "0", "ExecMainExitTimestampMonotonic": "0", "ExecMainPID": "0", "ExecMainCode": "0", "ExecMainStatus": "0", "ExecStart": "{ path=/bin/yes ; argv[]=/bin/yes ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", "ExecStartEx": "{ path=/bin/yes ; argv[]=/bin/yes ; flags= ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }", "Slice": "system.slice", "ControlGroupId": "0", "MemoryCurrent": "[not set]", "MemoryAvailable": "infinity", "CPUUsageNSec": "[not set]", "TasksCurrent": "[not set]", "IPIngressBytes": "[no data]", "IPIngressPackets": "[no data]", "IPEgressBytes": "[no data]", "IPEgressPackets": "[no data]", "IOReadBytes": "18446744073709551615", "IOReadOperations": "18446744073709551615", "IOWriteBytes": "18446744073709551615", "IOWriteOperations": "18446744073709551615", "Delegate": "no", "CPUAccounting": "yes", "CPUWeight": "[not set]", "StartupCPUWeight": "[not set]", "CPUShares": "[not set]", "StartupCPUShares": "[not set]", "CPUQuotaPerSecUSec": "infinity", "CPUQuotaPeriodUSec": "infinity", "IOAccounting": "no", "IOWeight": "[not set]", "StartupIOWeight": "[not set]", "BlockIOAccounting": "no", "BlockIOWeight": "[not set]", "StartupBlockIOWeight": "[not set]", "MemoryAccounting": "yes", "DefaultMemoryLow": "0", "DefaultMemoryMin": "0", "MemoryMin": "0", "MemoryLow": "0", "MemoryHigh": "infinity", "MemoryMax": "infinity", "MemorySwapMax": "infinity", "MemoryLimit": "infinity", "DevicePolicy": "auto", "TasksAccounting": "yes", "TasksMax": "455", "IPAccounting": "no", "ManagedOOMSwap": "auto", "ManagedOOMMemoryPressure": "auto", "ManagedOOMMemoryPressureLimit": "0", "ManagedOOMPreference": "none", "UMask": "0022", "LimitCPU": "infinity", "LimitCPUSoft": "infinity", "LimitFSIZE": "infinity", "LimitFSIZESoft": "infinity", "LimitDATA": "infinity", "LimitDATASoft": "infinity", "LimitSTACK": "infinity", "LimitSTACKSoft": "8388608", "LimitCORE": "infinity", "LimitCORESoft": "0", "LimitRSS": "infinity", "LimitRSSSoft": "infinity", "LimitNOFILE": "524288", "LimitNOFILESoft": "1024", "LimitAS": "infinity", "LimitASSoft": "infinity", "LimitNPROC": "1517", "LimitNPROCSoft": "1517", "LimitMEMLOCK": "8388608", "LimitMEMLOCKSoft": "8388608", "LimitLOCKS": "infinity", "LimitLOCKSSoft": "infinity", "LimitSIGPENDING": "1517", "LimitSIGPENDINGSoft": "1517", "LimitMSGQUEUE": "819200", "LimitMSGQUEUESoft": "819200", "LimitNICE": "0", "LimitNICESoft": "0", "LimitRTPRIO": "0", "LimitRTPRIOSoft": "0", "LimitRTTIME": "infinity", "LimitRTTIMESoft": "infinity", "OOMScoreAdjust": "0", "CoredumpFilter": "0x33", "Nice": "0", "IOSchedulingClass": "2", "IOSchedulingPriority": "4", "CPUSchedulingPolicy": "0", "CPUSchedulingPriority": "0", "CPUAffinityFromNUMA": "no", "NUMAPolicy": "n/a", "TimerSlackNSec": "50000", "CPUSchedulingResetOnFork": "no", "NonBlocking": "no", "StandardInput": "null", "StandardOutput": "journal", "StandardError": "inherit", "TTYReset": "no", "TTYVHangup": "no", "TTYVTDisallocate": "no", "SyslogPriority": "30", "SyslogLevelPrefix": "yes", "SyslogLevel": "6", "SyslogFacility": "3", "LogLevelMax": "-1", "LogRateLimitIntervalUSec": "0", "LogRateLimitBurst": "0", "SecureBits": "0", "CapabilityBoundingSet": "cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap cap_mac_override cap_mac_admin cap_syslog cap_wake_alarm cap_block_suspend cap_audit_read cap_perfmon cap_bpf cap_checkpoint_restore", "DynamicUser": "no", "RemoveIPC": "no", "PrivateTmp": "no", "PrivateDevices": "no", "ProtectClock": "no", "ProtectKernelTunables": "no", "ProtectKernelModules": "no", "ProtectKernelLogs": "no", "ProtectControlGroups": "no", "PrivateNetwork": "no", "PrivateUsers": "no", "PrivateMounts": "no", "PrivateIPC": "no", "ProtectHome": "no", "ProtectSystem": "no", "SameProcessGroup": "no", "UtmpMode": "init", "IgnoreSIGPIPE": "yes", "NoNewPrivileges": "no", "SystemCallErrorNumber": "2147483646", "LockPersonality": "no", "RuntimeDirectoryPreserve": "no", "RuntimeDirectoryMode": "0755", "StateDirectoryMode": "0755", "CacheDirectoryMode": "0755", "LogsDirectoryMode": "0755", "ConfigurationDirectoryMode": "0755", "TimeoutCleanUSec": "infinity", "MemoryDenyWriteExecute": "no", "RestrictRealtime": "no", "RestrictSUIDSGID": "no", "RestrictNamespaces": "no", "MountAPIVFS": "no", "KeyringMode": "private", "ProtectProc": "default", "ProcSubset": "all", "ProtectHostname": "no", "KillMode": "control-group", "KillSignal": "15", "RestartKillSignal": "15", "FinalKillSignal": "9", "SendSIGKILL": "yes", "SendSIGHUP": "no", "WatchdogSignal": "6", "Id": "baz.service", "Names": "baz.service", "Requires": "sysinit.target system.slice", "WantedBy": "multi-user.target", "Conflicts": "shutdown.target", "Before": "shutdown.target multi-user.target", "After": "basic.target system.slice sysinit.target systemd-journald.socket", "Description": "Baz Server", "LoadState": "loaded", "ActiveState": "inactive", "FreezerState": "running", "SubState": "dead", "FragmentPath": "/etc/systemd/system/baz.service", "UnitFileState": "enabled-runtime", "UnitFilePreset": "enabled", "StateChangeTimestamp": "Sat 2025-02-22 09:43:07 GMT", "StateChangeTimestampMonotonic": "4366308686", "InactiveExitTimestampMonotonic": "0", "ActiveEnterTimestampMonotonic": "0", "ActiveExitTimestampMonotonic": "0", "InactiveEnterTimestampMonotonic": "0", "CanStart": "yes", "CanStop": "yes", "CanReload": "no", "CanIsolate": "no", "CanFreeze": "yes", "StopWhenUnneeded": "no", "RefuseManualStart": "no", "RefuseManualStop": "no", "AllowIsolate": "no", "DefaultDependencies": "yes", "OnSuccessJobMode": "fail", "OnFailureJobMode": "replace", "IgnoreOnIsolate": "no", "NeedDaemonReload": "no", "JobTimeoutUSec": "infinity", "JobRunningTimeoutUSec": "infinity", "JobTimeoutAction": "none", "ConditionResult": "no", "AssertResult": "no", "ConditionTimestampMonotonic": "0", "AssertTimestampMonotonic": "0", "Transient": "no", "Perpetual": "no", "StartLimitIntervalUSec": "10s", "StartLimitBurst": "5", "StartLimitAction": "none", "FailureAction": "none", "SuccessAction": "none", "CollectMode": "inactive"}, "enabled": false, "invocation": {"module_args": {"name": "baz.service", "enabled": false, "daemon_reload": false, "daemon_reexec": false, "scope": "system", "no_block": false, "state": null, "force": null, "masked": null}}}\r\n', b"OpenSSH_8.9p1 Ubuntu-3ubuntu0.11, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/carl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/carl/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/carl/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2301978\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to pi closed.\r\n")
<pi> ESTABLISH SSH CONNECTION FOR USER: root
<pi> SSH: EXEC ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o Port=10322 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="root"' -o ConnectTimeout=10 -o 'ControlPath="/home/carl/.ansible/cp/232c16e386"' pi '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1740270764.0062406-2302436-38070915003900/ > /dev/null 2>&1 && sleep 0'"'"''
<pi> (0, b'', b"OpenSSH_8.9p1 Ubuntu-3ubuntu0.11, OpenSSL 3.0.2 15 Mar 2022\r\ndebug1: Reading configuration data /home/carl/.ssh/config\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files\r\ndebug1: /etc/ssh/ssh_config line 21: Applying options for *\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/carl/.ssh/known_hosts'\r\ndebug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/home/carl/.ssh/known_hosts2'\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 2301978\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n")
changed: [pi3] => {
    "changed": true,
    "enabled": false,
    "invocation": {
        "module_args": {
            "daemon_reexec": false,
            "daemon_reload": false,
            "enabled": false,
            "force": null,
            "masked": null,
            "name": "baz.service",
            "no_block": false,
            "scope": "system",
            "state": null
        }
    },
    "name": "baz.service",
    "status": {
        "ActiveEnterTimestampMonotonic": "0",
        "ActiveExitTimestampMonotonic": "0",
        "ActiveState": "inactive",
        "After": "basic.target system.slice sysinit.target systemd-journald.socket",
        "AllowIsolate": "no",
        "AssertResult": "no",
        "AssertTimestampMonotonic": "0",
        "Before": "shutdown.target multi-user.target",
        "BlockIOAccounting": "no",
        "BlockIOWeight": "[not set]",
        "CPUAccounting": "yes",
        "CPUAffinityFromNUMA": "no",
        "CPUQuotaPerSecUSec": "infinity",
        "CPUQuotaPeriodUSec": "infinity",
        "CPUSchedulingPolicy": "0",
        "CPUSchedulingPriority": "0",
        "CPUSchedulingResetOnFork": "no",
        "CPUShares": "[not set]",
        "CPUUsageNSec": "[not set]",
        "CPUWeight": "[not set]",
        "CacheDirectoryMode": "0755",
        "CanFreeze": "yes",
        "CanIsolate": "no",
        "CanReload": "no",
        "CanStart": "yes",
        "CanStop": "yes",
        "CapabilityBoundingSet": "cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap cap_mac_override cap_mac_admin cap_syslog cap_wake_alarm cap_block_suspend cap_audit_read cap_perfmon cap_bpf cap_checkpoint_restore",
        "CleanResult": "success",
        "CollectMode": "inactive",
        "ConditionResult": "no",
        "ConditionTimestampMonotonic": "0",
        "ConfigurationDirectoryMode": "0755",
        "Conflicts": "shutdown.target",
        "ControlGroupId": "0",
        "ControlPID": "0",
        "CoredumpFilter": "0x33",
        "DefaultDependencies": "yes",
        "DefaultMemoryLow": "0",
        "DefaultMemoryMin": "0",
        "Delegate": "no",
        "Description": "Baz Server",
        "DevicePolicy": "auto",
        "DynamicUser": "no",
        "ExecMainCode": "0",
        "ExecMainExitTimestampMonotonic": "0",
        "ExecMainPID": "0",
        "ExecMainStartTimestampMonotonic": "0",
        "ExecMainStatus": "0",
        "ExecStart": "{ path=/bin/yes ; argv[]=/bin/yes ; ignore_errors=no ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
        "ExecStartEx": "{ path=/bin/yes ; argv[]=/bin/yes ; flags= ; start_time=[n/a] ; stop_time=[n/a] ; pid=0 ; code=(null) ; status=0/0 }",
        "ExitType": "main",
        "FailureAction": "none",
        "FileDescriptorStoreMax": "0",
        "FinalKillSignal": "9",
        "FragmentPath": "/etc/systemd/system/baz.service",
        "FreezerState": "running",
        "GID": "[not set]",
        "GuessMainPID": "yes",
        "IOAccounting": "no",
        "IOReadBytes": "18446744073709551615",
        "IOReadOperations": "18446744073709551615",
        "IOSchedulingClass": "2",
        "IOSchedulingPriority": "4",
        "IOWeight": "[not set]",
        "IOWriteBytes": "18446744073709551615",
        "IOWriteOperations": "18446744073709551615",
        "IPAccounting": "no",
        "IPEgressBytes": "[no data]",
        "IPEgressPackets": "[no data]",
        "IPIngressBytes": "[no data]",
        "IPIngressPackets": "[no data]",
        "Id": "baz.service",
        "IgnoreOnIsolate": "no",
        "IgnoreSIGPIPE": "yes",
        "InactiveEnterTimestampMonotonic": "0",
        "InactiveExitTimestampMonotonic": "0",
        "JobRunningTimeoutUSec": "infinity",
        "JobTimeoutAction": "none",
        "JobTimeoutUSec": "infinity",
        "KeyringMode": "private",
        "KillMode": "control-group",
        "KillSignal": "15",
        "LimitAS": "infinity",
        "LimitASSoft": "infinity",
        "LimitCORE": "infinity",
        "LimitCORESoft": "0",
        "LimitCPU": "infinity",
        "LimitCPUSoft": "infinity",
        "LimitDATA": "infinity",
        "LimitDATASoft": "infinity",
        "LimitFSIZE": "infinity",
        "LimitFSIZESoft": "infinity",
        "LimitLOCKS": "infinity",
        "LimitLOCKSSoft": "infinity",
        "LimitMEMLOCK": "8388608",
        "LimitMEMLOCKSoft": "8388608",
        "LimitMSGQUEUE": "819200",
        "LimitMSGQUEUESoft": "819200",
        "LimitNICE": "0",
        "LimitNICESoft": "0",
        "LimitNOFILE": "524288",
        "LimitNOFILESoft": "1024",
        "LimitNPROC": "1517",
        "LimitNPROCSoft": "1517",
        "LimitRSS": "infinity",
        "LimitRSSSoft": "infinity",
        "LimitRTPRIO": "0",
        "LimitRTPRIOSoft": "0",
        "LimitRTTIME": "infinity",
        "LimitRTTIMESoft": "infinity",
        "LimitSIGPENDING": "1517",
        "LimitSIGPENDINGSoft": "1517",
        "LimitSTACK": "infinity",
        "LimitSTACKSoft": "8388608",
        "LoadState": "loaded",
        "LockPersonality": "no",
        "LogLevelMax": "-1",
        "LogRateLimitBurst": "0",
        "LogRateLimitIntervalUSec": "0",
        "LogsDirectoryMode": "0755",
        "MainPID": "0",
        "ManagedOOMMemoryPressure": "auto",
        "ManagedOOMMemoryPressureLimit": "0",
        "ManagedOOMPreference": "none",
        "ManagedOOMSwap": "auto",
        "MemoryAccounting": "yes",
        "MemoryAvailable": "infinity",
        "MemoryCurrent": "[not set]",
        "MemoryDenyWriteExecute": "no",
        "MemoryHigh": "infinity",
        "MemoryLimit": "infinity",
        "MemoryLow": "0",
        "MemoryMax": "infinity",
        "MemoryMin": "0",
        "MemorySwapMax": "infinity",
        "MountAPIVFS": "no",
        "NFileDescriptorStore": "0",
        "NRestarts": "0",
        "NUMAPolicy": "n/a",
        "Names": "baz.service",
        "NeedDaemonReload": "no",
        "Nice": "0",
        "NoNewPrivileges": "no",
        "NonBlocking": "no",
        "NotifyAccess": "none",
        "OOMPolicy": "stop",
        "OOMScoreAdjust": "0",
        "OnFailureJobMode": "replace",
        "OnSuccessJobMode": "fail",
        "Perpetual": "no",
        "PrivateDevices": "no",
        "PrivateIPC": "no",
        "PrivateMounts": "no",
        "PrivateNetwork": "no",
        "PrivateTmp": "no",
        "PrivateUsers": "no",
        "ProcSubset": "all",
        "ProtectClock": "no",
        "ProtectControlGroups": "no",
        "ProtectHome": "no",
        "ProtectHostname": "no",
        "ProtectKernelLogs": "no",
        "ProtectKernelModules": "no",
        "ProtectKernelTunables": "no",
        "ProtectProc": "default",
        "ProtectSystem": "no",
        "RefuseManualStart": "no",
        "RefuseManualStop": "no",
        "ReloadResult": "success",
        "RemainAfterExit": "no",
        "RemoveIPC": "no",
        "Requires": "sysinit.target system.slice",
        "Restart": "no",
        "RestartKillSignal": "15",
        "RestartUSec": "100ms",
        "RestrictNamespaces": "no",
        "RestrictRealtime": "no",
        "RestrictSUIDSGID": "no",
        "Result": "success",
        "RootDirectoryStartOnly": "no",
        "RuntimeDirectoryMode": "0755",
        "RuntimeDirectoryPreserve": "no",
        "RuntimeMaxUSec": "infinity",
        "RuntimeRandomizedExtraUSec": "0",
        "SameProcessGroup": "no",
        "SecureBits": "0",
        "SendSIGHUP": "no",
        "SendSIGKILL": "yes",
        "Slice": "system.slice",
        "StandardError": "inherit",
        "StandardInput": "null",
        "StandardOutput": "journal",
        "StartLimitAction": "none",
        "StartLimitBurst": "5",
        "StartLimitIntervalUSec": "10s",
        "StartupBlockIOWeight": "[not set]",
        "StartupCPUShares": "[not set]",
        "StartupCPUWeight": "[not set]",
        "StartupIOWeight": "[not set]",
        "StateChangeTimestamp": "Sat 2025-02-22 09:43:07 GMT",
        "StateChangeTimestampMonotonic": "4366308686",
        "StateDirectoryMode": "0755",
        "StatusErrno": "0",
        "StopWhenUnneeded": "no",
        "SubState": "dead",
        "SuccessAction": "none",
        "SyslogFacility": "3",
        "SyslogLevel": "6",
        "SyslogLevelPrefix": "yes",
        "SyslogPriority": "30",
        "SystemCallErrorNumber": "2147483646",
        "TTYReset": "no",
        "TTYVHangup": "no",
        "TTYVTDisallocate": "no",
        "TasksAccounting": "yes",
        "TasksCurrent": "[not set]",
        "TasksMax": "455",
        "TimeoutAbortUSec": "1min 30s",
        "TimeoutCleanUSec": "infinity",
        "TimeoutStartFailureMode": "terminate",
        "TimeoutStartUSec": "1min 30s",
        "TimeoutStopFailureMode": "terminate",
        "TimeoutStopUSec": "1min 30s",
        "TimerSlackNSec": "50000",
        "Transient": "no",
        "Type": "simple",
        "UID": "[not set]",
        "UMask": "0022",
        "UnitFilePreset": "enabled",
        "UnitFileState": "enabled-runtime",
        "UtmpMode": "init",
        "WantedBy": "multi-user.target",
        "WatchdogSignal": "6",
        "WatchdogTimestampMonotonic": "0",
        "WatchdogUSec": "infinity"
    }
}

TASK [systemd : assert] *******************************************************************************************
task path: /home/carl/src/bug_reports/ansible/test/integration/targets/systemd/tasks/test_enabled_runtime.yml:42
fatal: [pi3]: FAILED! => {
    "assertion": "baz_test_1 is changed",
    "changed": false,
    "evaluated_to": false,
    "msg": "Assertion failed"
}

PLAY RECAP ********************************************************************************************************
pi3 : ok=37 changed=11 unreachable=0 failed=1 skipped=0 rescued=0 ignored=2

```

pi (port 10322) is a pi with a fairly vinalla raspi os install, which is pretty close to Debian. I would be surprised if the differences are relevant to getting the ansible tests to pass.

I can bring up an x86 Debian proper box, but that takes me 10 minutes and some fidelly keyboarding to re-image. the pi is under a minute, so easy to ansible it, inspect, reset.

---

<div class="post-metadata">

**Author:** ![NomakCooper](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nomakcooper/32/7309_2.png) [@NomakCooper](https://forum.ansible.com/u/NomakCooper)\
**Post date:** [February 23, 2025, 6:07pm UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/6 "2025-02-23T18:07:00Z")

</div>

First of all, in order to understand what is happening, it’s necessary to know which version of Ansible you are using.

```bash
# ansible --version

```

The integration test I mentioned earlier is the one currently present in the devel branch and therefore refers to ansible **`2.18.2`**.

If you are using an earlier version, the code for the **`systemd_service`** module might be different.

---

<div class="post-metadata">

**Author:** ![CarlFK](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/carlfk/32/7668_2.png) [@CarlFK](https://forum.ansible.com/u/CarlFK)\
**Post date:** [February 23, 2025, 6:58pm UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/7 "2025-02-23T18:58:21Z")

</div>

I was on 2.17. I couldn’t figure out how to get 1.18, but git checkout gives me 1.19 and the tests pass.

For my personal project that I am working on, I am happy to use this.  
So this is progress.  
Maybe this fixes all my problems! (probably not, but who knows.)

---

<div class="post-metadata">

**Author:** ![NomakCooper](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nomakcooper/32/7309_2.png) [@NomakCooper](https://forum.ansible.com/u/NomakCooper)\
**Post date:** [February 23, 2025, 7:02pm UTC](https://forum.ansible.com/t/systemd-test-enabled-workaround/40520/8 "2025-02-23T19:02:32Z")

</div>

@CarlFK

I think you’re not using the latest version of Ansible ( **`2.18.2`** ).

The recognition of services in **`enabled-runtime`** and the corresponding integration test were introduced with commit [3076478](https://github.com/ansible/ansible/commit/3076478892735bd33fd79c14acf3635d004f859f) on April 10, 2024 via PR [#77754](https://github.com/ansible/ansible/pull/77754), which was opened in 2022.

> Extend systemctl is-enabled check to handle “enabled-runtime” too. ([#77754](https://github.com/ansible/ansible/pull/77754))
> 
> In general the existence of a runtime-enabled unit should not prevent a persistent enable being set.  
> Specifically this handles the case where there is an entry in fstab for a mount point (which is retained to allow manual mount/umount to take place) and yet a systemd mount unit needs to be deployed to handle other unit options.  
> There will be a generator-created unit file which shows the unit as enabled-runtime and the persistent enable of the mount unit will fail. Additionally improve the comments and modify the code to use rsplit() and the “in” notation since “systemctl is-enabled” is documented to return specific values in the cases of interest.

In fact, I ran a test with my ansible-core control node **`2.18.2`** , and the **`systemd_service`** module correctly enables a service that is in **`enabled-runtime`**.

```bash
# ansible --version
ansible [core 2.18.2]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.5 (main, Jan 27 2025, 22:17:48) [GCC 11.5.0 20240719 (Red Hat 11.5.0-2)] (/usr/local/bin/python3.11)
  jinja version = 3.1.5
  libyaml = True

```

Playbook:

```yaml
---
- name: dummy baz service test
  hosts: localhost

  tasks:

    - name: Copy dummy.service file
      copy:
        dest: /etc/systemd/system/baz.service
        content: |
          [Unit]
          Description=Baz Service

          [Service]
          ExecStart=/bin/yes
          ExecReload=/bin/true
          Type=forking
          PIDFile=/var/run/baz_service.pid

          [Install]
          WantedBy=multi-user.target
        owner: root
        group: root
        mode: '0644'

    - name: Reload systemd
      ansible.builtin.systemd_service:
        daemon_reload: true

    - name: Enable the enabled-runtime service using shell command
      shell: systemctl enable --runtime baz.service

    - name: is-enabled test pre
      shell: systemctl is-enabled baz.service
      register: is_enabled_pre

    - name: debug is-enabled pre
      debug:
        var: is_enabled_pre.stdout

    - name: systemctl show files pre
      ansible.builtin.shell: systemctl list-unit-files | grep -w baz.service
      register: props_pre

    - name: debug props pre
      debug:
        var: props_pre.stdout_lines

    - name: Enable enabled-runtime service
      ansible.builtin.systemd_service:
        name: baz.service
        enabled: true
      register: baz_test_1

    - name: is-enabled test post
      shell: systemctl is-enabled baz.service
      register: is_enabled_post

    - name: debug is-enabled post
      debug:
        var: is_enabled_post.stdout

    - name: systemctl show files post
      ansible.builtin.shell: systemctl list-unit-files | grep -w baz.service
      register: props_post

    - name: debug props post
      debug:
        var: props_post.stdout_lines

```

result debug:

```bash
TASK [debug is-enabled pre] ************************************************************
ok: [localhost] => {
    "is_enabled_pre.stdout": "enabled-runtime"
}

TASK [debug props pre] *****************************************************************
ok: [localhost] => {
    "props_pre.stdout_lines": [
        "baz.service enabled-runtime disabled"
    ]
}

TASK [debug is-enabled post] ***********************************************************
ok: [localhost] => {
    "is_enabled_post.stdout": "enabled"
}

TASK [debug props post] ****************************************************************
ok: [localhost] => {
    "props_post.stdout_lines": [
        "baz.service enabled disabled"
    ]
}

```
