--- - name: check isc-dhcp-server ansible.builtin.service_facts: listen: restart isc-dhcp-server - name: restart dhcp server ansible.builtin.systemd: name: isc-dhcp-server state: restarted listen: restart isc-dhcp-server when: not ansible_check_mode and ansible_facts.services['isc-dhcp-server']['state'] == 'running'