ansible-role-systemd icon indicating copy to clipboard operation
ansible-role-systemd copied to clipboard

[Feature Request] Keep current state if `state` is not set

Open hkcomori opened this issue 1 year ago • 0 comments

Expected behavior

I want the current state of the service to continue if the state value is not set.

For example, in the use case of adding ExecStop to an already active unit file, I want only daemon-reload to be executed and not restart the service.

This way, the service will continue to run and the new configuration (ExecStop) will be executed the next time it is stopped.

There are several other changes that do not require a restart.

  • No effect on behavior at all: Description
  • Affects only start timing: After, Before, Wants, ...

Current behavior

The service is stopped once when the unit file is rewritten in this role.

If state and enabled are not set, the following default values apply.

https://github.com/O1ahmad/ansible-role-systemd/blob/9a0ba98eeb2df5436674a28f6b7f9bb9a6e8aa84/defaults/main.yml#L6

If state: started is set, it is replaced by restarted and applied.

https://github.com/O1ahmad/ansible-role-systemd/blob/9a0ba98eeb2df5436674a28f6b7f9bb9a6e8aa84/handlers/main.yml#L6

Therefore, nothing I set to state will keep the service in an active state.

Proposed change

Since it is difficult to detect whether or not a restart is required, I think it is better to simply run the systemd module without setting the state if the state is not set.

hkcomori avatar Feb 28 '24 00:02 hkcomori