79529412

Date: 2025-03-23 18:19:18
Score: 0.5
Natty:
Report link

The cleanest solution I found was to register a variable with the Restart Service handler then check if the variable was defined when the Reload Service handler gets called. Other solutions tried to handle this in the playbook task or with set_fact but those all had issues. This is the solution that work for me in Ansible 2.16 and couldcan be implemented without modification of the playbook/role task blocks:

- name: Restart Service
  become: yes
  systemd:
    name: some.service
    state: restarted
    enabled: yes
  # Register service restart to prevent a service reload
  register: service_restarted

- name: Reload Service
  become: yes
  systemd:
    name: some.service
    state: reloaded
    enabled: yes
  when: "service_restarted is undefined"
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Slez-E