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"