#84793·ansible

Different behavior for `state: restarted` in the `ansible.builtin.service` module (FreeBSD)

Author: ohauckeCreated Mar 7, 2025Updated Sep 26, 2026
Labelsmodulebughas_prneeds_verified

Summary

The state: restarted in the ansible.builtin.service module differs from the others (started, stopped and reloaded) of the implementation in FreeBSD: https://github.com/ansible/ansible/blob/09391f38f009ec58b5759dbd74df34fd281ef3ac/lib/ansible/modules/service.py#L1090-L1099

With the current implementation started, stopped and reloaded execute the corresponding action even if the service is disabled, only restarted will have no effect when the service is disabled.

Option 1

Add the following part - to be consistent with the rest

if self.action == "restart":
  self.action = "onerestart"

Option 2

Omit the start/stop modification - to match the documentation

_

I would prefer option 1 but that's just my opinion.

Issue Type

Bug Report

Component Name

ansible.builtin.service

Ansible Version

bash
$ ansible --version
N/A

Configuration

bash
# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
N/A

OS / Environment

FreeBSD

Steps to Reproduce

yaml
- name: Restart apache24
  become: true
  ansible.builtin.service:
    name: "apache24"
    state: "restarted"

Expected Results

N/A

Actual Results

bash
N/A

Code of Conduct

  • I agree to follow the Ansible Code of Conduct